TurboGears: Integrating with Apache

Documentation on running Apache as a frontend to a TurboGears server can be found at the CherryPy Wiki.

One issue not addressed there is inconsistent character sets. The default Kid templates used by TurboGears specify a charset of utf-8. The Apache default charset, returned in the "Content-Type" header, is ISO-8859-1. This inconsistency will cause errors during validation and incorrect rendering of some characters on the client. Use this directive to override the Apache default:

 AddDefaultCharset utf-8

You can also explicitly set the charset property in the Content-Type header from cherrypy:

 cherrypy.response.headerMap["Content-Type"] += ";charset=utf-8" 

That way, since a charset is specified, Apache won't apply the default charset.

Note that you can't use _cpFilterList, you have to make the filter changes to the config file, like so:

 [/]
 baseUrlFilter.on = True
 baseUrlFilter.useXForwardedHost = True

Another Example

Karl Guertin wrote a step-by-step set of instructions in this message on using VirtualPathFilter with Apache.

  1. Put the following lines in your prodcfg.py:
     path("/")
     baseUrlFilter.on = True
     baseUrlFilter.useXForwardedHost = True
    
  2. In your app directory run 'python setup.py bdist_egg' to create an installable egg file.
  3. Copy the egg to your server and easy_install your_app_name
  4. Create an Apache virtual host containing the following rules:
     RewriteEngine on
     RewriteRule ^(.*) http://127.0.0.1:8000$1 [P]
    
  5. Restart Apache

There are other things you can optionally do and caveats, but the above should work just fine. I'm not 100% sure on the syntax of the first step, I've only deployed using the old .cfg format.