Timur Izhbulatov — Independent Electronic Music

TurboGears behind Apache with Virtualmin

Wed, 19 Mar 2008 11:05:00 in Tech stuff | permalink

apache cherrypy debian linux python turbogears virtualmin webmin

Recently Matvey (thanks dude!) has set up a new Virtualmin hosting platform on Debian GNU/Linux. When I was migrating timka.org to this new platform I found out that Virtualmin is actually very powerful and nicely integrated with Apache in Debian. Looking at all these new features and capabilities I thought that I could try to use them for running home-based TurboGears applications on Virutalmin's virtual hosts.

The idea of running web applications behind Apache as separate processes is described in both TurboGears and CherryPy documentation. Obviously, any of these configurations requires write access to Apache config file. So, you can't follow the instructions from official docs directly, if you're not allowed to manually edit Apache's configuration directives in Webmin. Fortunately, it is possible to configure Apache to serve as proxy for your application through Webmin UI without editing directives manually.

First of all, you need to configure and deploy your application on target host. In my previous post I wrote about home-based installation of Python projects. I used this approach again to deploy my application and its dependencies. I also added the following lines to my application's deployment-specific configuration file (usually, it's prod.cfg or dev.cfg):

# Stolen from http://docs.turbogears.org/1.0/BehindApache
base_url_filter.on = True
base_url_filter.use_x_forwarded_host = True

server.socket_host="127.0.0.1"
server.socket_port=8080
After that start the application using it's startup script as usuall.

When the application is up and running, you need to create a virtual host for it in Virutalmin. The options I used are shown on the screenshot. The essential things here are DNS zone, website and the forwarding part. Probably, you'll also need a database.

Next, in the 'Proxying' properties of 'Apache Webserver' on your newly created virtual server you need to enable 'Preserve original Host header' (the ProxyPreserveHost directive). Also, if you want Apache to serve static content, add a ProxyPass directive for the /static/ location to prevent it from being proxied. This can be done on the 'Aliases and Redirects' properties page (screenshot).

After that your virtual host's configuration should contain the following directives:

ProxyPass /static/ !
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
<Proxy *>
allow from all
</Proxy>
ProxyPreserveHost On
This result reproduces the mod_proxy approach presented in CherryPy documentation.

If the configuration looks OK, you can apply the changes and check that the site is available. For instance, using this command:

$ wget -O - http://yourapp.yoursite.com

You should see your application's front page on standard output. Bear in mind that change propagation in DNS takes some time. You may need to wait or add a line to your hosts file, if you're using DNS servers other than serve the web site's zone.