Skip to content

Instantly share code, notes, and snippets.

Last active December 30, 2016 14:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Deploying a Python Web App on Azure

NOTE: For more up-to-date instructions and more explanations, please see the readme of

Basic instructions

  1. Add a new Web App

  2. Go to and click on Site Extensions

  3. Install the Python 2.7.12 x64 and IIS Manager extensions. Click on Restart site when both are installed.

  4. Under the installed site extensions, click on the play (▶) button for IIS Manager.

  5. Go to the applicationHost.xdt tab

  6. Enter the following contents:

    <?xml version="1.0"?>
    <configuration xmlns:xdt="">
              <environmentVariable name="PYTHONHOME" value="D:\home\Python27" />
      <location path="%XDT_SITENAME%" xdt:Transform="InsertIfMissing" xdt:Locator="Match(path)">
        <system.webServer xdt:Transform="InsertIfMissing">
          <applicationInitialization xdt:Transform="InsertIfMissing">
            <add initializationPage="/"  xdt:Transform="InsertIfMissing"/>
          <rewrite xdt:Transform="InsertIfMissing">
            <rules xdt:Transform="InsertIfMissing">
              <rule name="Force HTTPS" enabled="true" stopProcessing="true">
                <match url="(.*)" ignoreCase="false" />
                  <add input="{HTTPS}" pattern="off" />
                  <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />

    You may omit the <location> block if you wish, but this forces HTTPS.

  7. Click on Save XDT. Stop the application from the portal, before starting again (I find that it might take more than one restart for the change to pick up)

  8. On the client side, modify the deployment script to use the extension Python:

    npm install -g azure-cli
    azure config mode asm
    azure site deploymentscript --python

    Replace everything in the SelectPythonVersion section in deploy.cmd with:

    SET PYTHON_RUNTIME=python-2.7
    SET PYTHON_EXE=%SYSTEMDRIVE%\home\python27\python.exe
    SET PYTHON_ENV_MODULE=virtualenv

    The goal is to replace D:\Python27 with D:\home\Python27

  9. The contents of web.config should be similar to below:

    <?xml version="1.0"?>
        <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="wsgi.application" />
             value="D:\home\site\wwwroot\env\Scripts\" />
        <add key="WSGI_HANDLER"
             value="ptvs_virtualenv_proxy.get_virtualenv_handler()" />
        <add key="WSGI_LOG" value="D:\home\site\wwwroot\log.txt" />
        <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
        <compilation debug="true" targetFramework="4.0" />
          <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python27\python.exe|D:\home\Python27\" resourceType="Unspecified" requireAccess="Script"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment