Web.config environment variables missing in Azure
See original GitHub issueTL;DR Some environment variables present in the web.config (like ROOTDIR) generated by PTVS are missing in Azure. This causes a deployment to “fail” because even tho the code is deployed, the site doesn’t run. Replacing the variables with hardcoded values solves the issue.
Am I supposed to have those variables set in my Web App automagically by Azure or am I supposed to treat those variables as placeholders and edit my web.config with the appropriate values?
Howdy,
I had an issue happening to me every time I tried to use PTVS and Azure, so I just downloaded the latest version both Visual Studio and PTVS, did a File->New Django project and published it to an Azure Web App.
This is the web.config generated by PTVS:
<?xml version="1.0"?>
<!-- Generated web.config for Microsoft Azure. Remove this comment to prevent
modifications being overwritten when publishing the project.
-->
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<appSettings>
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="%ROOTDIR%\env\Scripts\python.exe" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" />
<add key="PYTHONPATH" value="%ROOTDIR%" />
<add key="DJANGO_SETTINGS_MODULE" value="djangotest.settings" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="%INTERPRETERPATH%|%WFASTCGIPATH%" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
As you can see, this config file “depends” on the presence of some variables to work, namely ROOTDIR, INTERPRETERPATH and WFASTCGIPATH.
Those variables don’t seem to be present on my Azure Web App, even after I properly configured the site to use python 3.4, but if I replace those variables with hardcoded values (ROOTDIR with D:\home\site\wwwroot\ and so on) then the Web App works beautifully.
Tested with both python 2.7, 3.4 and 3.5 (using extensions) and it’s the same thing no matter which python version: no variables present.
Am I supposed to have those variables set in my Web App automagically by Azure or am I supposed to treat those variables as placeholders and edit my web.config with the appropriate values?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
We already have issue #1684 to fix a genuine bug in the template, so I’ll add a note there and close this. Thanks for the feedback!
Also see this post https://blogs.msdn.microsoft.com/pythonengineering/2016/08/04/upgrading-python-on-azure-app-service/
It has some sample web.configs for App Service that are much shorter. The code we generate is far more complicated than it needs to be (if you know how to edit it manually, that is 😃 ).