antoinemartin / django-windows-tools

Django application providing management commands to host Django projects in Windows environments
BSD 2-Clause "Simplified" License
50 stars 13 forks source link

Suggestion: Use wfastcgi for serving instead #31

Open beruic opened 6 years ago

beruic commented 6 years ago

I am sorry to say that I have not been able to use django-windows-tools for deploying. I have however found a simple way of deploying in IIS with wfastcgi and will share my experiences in the hope that it may improve this project.

Basically I added a FastCGI application from my virtual environment with full path being [venv_root]\Scripts\python.exe and arguments being [venv_root]\Lib\site-packages\wfastcgi.py. This is automated by wfastcgi by the installed command wfastcgi-enable (there is also a wfastcgi-disable for removing it again).

Then I add my site root as a new site using the following template to create the web.config (Note that [site_root], [venv_root] and [project_module] must be replaced):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <clear/>
      <add name="FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="[venv_root]\Scripts\python.exe|[venv_root]\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
  </system.webServer>

  <appSettings>
    <!-- Required settings -->
    <add key="PYTHONPATH" value="[site_root]" />
    <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="DJANGO_SETTINGS_MODULE" value="[project_module].settings" />
    <add key="DEBUG" value="False" />

    <!-- Optional settings -->
    <!--<add key="WSGI_LOG" value="[log_path]" />-->
  </appSettings>

  <!-- Serve the collected static files -->
  <location path="static">
    <system.webServer>
      <handlers>
        <clear/>
        <add name="StaticFiles" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read"/>
      </handlers>
    </system.webServer>
  </location>

</configuration>

This setup requires that STATIC_URL = '/static/' and STATIC_ROOT = os.path.join(BASE_DIR, 'static') to avoid creating a virtual directory in IIS, but I guess that can be automated.

You may also want to give full access to the site root to the app pool user.

Other than that, my only caveat is that I don't use MEDIA in my project, but I guess that is just a matter of repeating the procedure for static.

mrbean-bremen commented 6 years ago

Thanks for that! I wasn't aware of wfastcgi (thanks, Microsoft!), this is a good pointer for people having problems with this package. I may put a note into the README later. This project is not really maintained anymore. Also, the Celery part does not work anymore, as Celery is no more supported under Windows. I personally still use the fastcgi part at work for a client, as it it's quite convenient, and from time to time someone else still seems to use it, but the traffic is generally quite low. I did some minor fixes occassionally, and I may continue to do so, but I don't have a server system available for testing either. Also, I see that even under Windows, django is nowadays often run in a container (e.g. in the Windows docker client), so I don't see much future demand for this package.

beruic commented 6 years ago

Well, my reason for looking into this package, is that you cannot run a Linux container on Windows without virtualization. So when your the host machine provided to you is a virtual Windows server, you have no choice. I guess this will hold true until the Windows Subsystem for Linux is more widely available (because the Windows server versions you generally get is newer), and mature (so it can run services upon boot).