title: Django / Azure : serving static files in production
body: <p>I want to deploy a Django website hosted in an Azure Web App.</p>
  
  <p>The static files are served perfectly in DEBUG mode (DEBUG=False), but I can't find the right settings to have the server take care of it in production. All my static files are collected in a "static" directory at the app root wwwroot/static/.</p>
  
  <p>Here is the <strong>web.config</strong>, at the root of the application.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;    
  &lt;configuration&gt;
  &lt;appSettings&gt;
    &lt;add key="WSGI_ALT_VIRTUALENV_HANDLER" value="MyApp.wsgi.application" /&gt;
    &lt;add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\python.exe" /&gt;
    &lt;add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" /&gt;
    &lt;add key="PYTHONPATH" value="D:\home\site\wwwroot" /&gt;
    &lt;add key="DJANGO_SETTINGS_MODULE" value="MyApp.settings" /&gt;
    &lt;add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgit.log"/&gt;
  &lt;/appSettings&gt;
  &lt;system.webServer&gt;
    &lt;handlers&gt;
      &lt;add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/&gt;
    &lt;/handlers&gt;
    &lt;rewrite&gt;
      &lt;rules&gt;
        &lt;rule name="Static Files" stopProcessing="true"&gt;
          &lt;conditions&gt;
            &lt;add input="true" pattern="false" /&gt;
          &lt;/conditions&gt;
        &lt;/rule&gt;
        &lt;rule name="Configure Python" stopProcessing="true"&gt;
          &lt;match url="(.*)" ignoreCase="false" /&gt;
          &lt;action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" /&gt;
        &lt;/rule&gt;
      &lt;/rules&gt;
    &lt;/rewrite&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p></p>
  
  <p>I also added the following <strong>web.config</strong> in the static directory:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;  
  &lt;configuration&gt;  
  &lt;system.webServer&gt;
      &lt;!-- this configuration overrides the FastCGI handler to let IIS serve the static files --&gt;
      &lt;handlers&gt;
         &lt;clear /&gt;
          &lt;add 
              name="StaticFile"
              path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" 
              resourceType="Either" 
              requireAccess="Read" /&gt;
      &lt;/handlers&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>  </p>
  
  <p>I also defined the static directory as a "virtual directory" in the web app settings, with "\static" refering to "\site\wwwroot\static", and checking the "application" checkbox (i also tried to leave it unchecked but it does not change anything.</p>
  
  <p>However, this is not working. </p>
  
  <p>1) Is it possible to setup an Azure web app to serve the static files in production without using a CDN?</p>
  
  <p>2) If yes, how to do it?</p>