Tag: azure

Deploying Python App to AzureWebsites

Deploying Python App to AzureWebsites

Note: This was originally created on my azurewebsite that I learned to deploy with and can be found on my github page.

I have only been programming in Python for a few months (December 2016 to March 2017) when I decided to deploy a simple Flask app to Azure. I found that the documentation was lacking, confusing and written for someone who knew both Azure deployments and Python well which is not me.

So this is the result of what I have learned so far.
What you will need 1) an Azure account, 2) FTP Client like FileZilla, and 3) some type of IDE or text editor (Notepad, Note++ or Visual Studio Code – what I use).

Deploying a Simple Site

First, you will need an Azure account. Signup for the free tier, which allows 10 Azure Websites and 1 GB of storage (as of March 2017).

Once you have signed up to Azure.

Create a New website. Web + Mobile > See All > Search for Flask > then Create your site. Once deployed you will be able to download it via FTP.

The template looks like this.
Changes for you app


Under appsettings change the FlaskWebProject1.app to whatever your app name is (folder).

Under rewrite node find the action type node url=”^/FlaskWebProject1/static/.* to you app name (folder).

App Folder Name

Change the name of the folder to whatever you named the application in web.config.
Change the from FlaskWebProject1 import app to your applications name.
Change the import FlaskWebProject1.views to your applications name.


Change from FlaskWebProject1 import app to your applications name.
Then run your application (python runserver.py) to make sure it all works. Default is localhost:5555, but I changed the port to 5000 and it has been running fine. If you are using a virtual environment ( pip install virtualenv and then env\Scripts\activate) then then make sure you have installed the requirements.txt ( pip install -r requirements.txt).

FTP your site to Azure

With your site working locally (localhost), its time to upload it to Azure. On the Azure portal for your Website, select QuickStart and Python. There are several options to deploy your application to Azure, for now we will use FTP. Select that as your option and follow the directions.


Once you have your credentials setup, use an FTP Client like FileZilla (what I am using) and setup a connection.

Once you have connected to Azure, load the entire contents of the site into Site > wwwroot.

It can take a few minutes for Azure to get your application running. But you should have your site up and running now.

Azure VM – Network Security Group

Azure VM – Network Security Group

Recently I created a new virtual machine on Azure. It’s been awhile since I’ve had one, so I went through securing it. Made sure I had a firewall running and using Fail2Ban to stop brute force attacks. Or at least I thought…

I found that I was banning IP addresses by the hundreds a day trying to log into SSH. Seriously, what the hell! 90% where from China so I looked into seeing if I could ban whole countries. That just seemed extreme. It occurred to me to just allow logging in with specific IP addresses, like from my home or work.

On the server itself, I found this to not actually stop the attempts. Since they could still try to log in. So instead I used Azure’s Network Security Group to limit access to just my home IP address. This means I can edit access if needed, but prevent the endless hacking from China, Russia, Ukraine, and other locations.

Nothing against, those countries, but I don’t need the security hassle from whomever is really hacking me.

On a side note – The recent hacking of the US Democratic Party (DNC and John Podesta) during the 2016 election cycles, really shows how poorly people take security. I am no expert, but come on… Password as your password? That is just stupid.