Notes on mod_wsgi

Good information here:

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines

In particular, I finally have a clear explanation for why blosxom and other frameworks give you the option to override the base url. It's for this situation:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /site.wsgi/$1 [QSA,PT,L]

The SCRIPT_NAME in this case is /site.wsgi. Flask, for example, uses this variable to construct its URLs via url_for. So even though your site is off of root, your URLs will be off of site.wsgi. An easy way to get around this is to fix your WSGI script:

def _application(environ, start_response):
    # The original application.
    ...

import posixpath

def application(environ, start_response):
    # Wrapper to set SCRIPT_NAME to actual mount point.
    environ['SCRIPT_NAME'] = posixpath.dirname(environ['SCRIPT_NAME'])
    if environ['SCRIPT_NAME'] == '/':
        environ['SCRIPT_NAME'] = ''
    return _application(environ, start_response)

This basically munges the SCRIPT_NAME variable properly.

ModWsgiNotes (last edited 2012-07-14 01:52:02 by DesmondRivet)