wfastcgi.py provides a gateway between IIS's FastCGI support to Python's WSGI protocol. It can be downloaded off of the releases page.

Installing & Configuring

1. Download and install wfastcgi, it will install into C:\Python27\Scripts (or wherever your Python interpreter is installed).

2. Make sure IIS has FastCGI installed:

start /wait %windir%\System32\\PkgMgr.exe /iu:IIS-CGI

3. Register the handler with IIS:

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI "/+[fullPath='c:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py']"

Using in an application

You can now use the handler in a web.config file, here's an example configured for a Django project:

    <appSettings>
        <add key="WSGI_HANDLER" value="django.core.handlers.wsgi.WSGIHandler()" />
        <add key="DJANGO_SETTINGS_MODULE" value="DjangoProject.settings" />   
    </appSettings>
    <system.webServer>
        <handlers>
            <add name="Python_FastCGI"
                path="handler.fcgi"
                verb="*"
                modules="FastCgiModule"
                scriptProcessor="C:\Python27\python.exe|C:\Python27\Scripts\wfastcgi.py"
                resourceType="Either"
                requireAccess="Script" />
        </handlers>
        <rewrite>
            <rules>
                <rule name="Django Application" stopProcessing="true">
                    <match url="(.*)" ignoreCase="false" />
                    <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>


You can tweak the URL rewriting to include or exclude certain paths for serving static files or other requests from the same server.

Options

Options are specified with an appSetting in your top-level web.config file as WSGI_HANDLER is shown in the example above.

Option Name Description
WSGI_HANDLER Specifies the fully qualified handle name, such as "mymodule.handler" or "mymodule.package.handler". The module name will be imported and the specified handler name will be accessed. If the handler name ends in "()" the handler will be called with no arguments. If the handler cannot be fetched or is None wfastcgi will exit and log the error if WSGI_LOG is set.
WSGI_RESTART_FILE_REGEX Specifies the regex for the filenames which if modified will cause wfastcgi to exit and be restarted. Defaults to ".*((\.py)|(\.config))$".
WSGI_LOG Specifies the path to a log file of errors and important messages.

Last edited Jul 2, 2013 at 11:33 PM by dinov, version 8

Comments

No comments yet.