Ubuntu, lighttpd reverse proxy to apache python for django
Not Complete This is a brief note I will update over time to reflect my current setup for serving django with lighty proxying requests.
Benifits of proxying
The benefits of proxying web-requests has been well documented in recent times. Lower over head for serving static files like html, javascript, css and images. In my convoluted setup I am using lighttpd to serve most of my static content which is far faster than using apache with the inherent overhead of python and php and other modules every time a file is requested.
Install the needed software
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2-mpm-worker apache2-threaded-dev lighttpd libapache2-mod-python
Apache Configuration
I have configured apache to listen on port 81 and blocked it from pubic access at the firewall because I will be using lighttpd to proxy requests to apache . I also have disabled apache logging as it will be handled by lighttpd.
Virtual Host
<VirtualHost *:81>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/websites/example.com/myapp
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myapp.settings
PythonPath "['/home/websites/example.com/']+sys.path"
PythonDebug Off
</Location>
</VirtualHost>
Lighttpd Configuration
Modules for lighttpd
server.modules += ( "mod_proxy","mod_rewrite", "mod_fastcgi", "mod_status","mod_cgi", "mod_redirect" )
The static lighttpd server
$HTTP["host"] == "media.example.com" {
server.document-root = "/home/websites/example.com/media_root"
server.errorlog = "/home/websites/example.com/logs/media-error.log"
accesslog.filename = "/home/websites/example.com/logs/media-access.log"
}
The proxy entry
else $HTTP["host"] =~ "(^|\.)example\.com$" {
proxy.server = ( "" => ( ( "host" => "127.0.0.1","port" => 81 )))
server.errorlog = "/home/websites/example.com/logs/proxy-error.log"
accesslog.filename = "/home/websites/example.com/logs/proxy-access.log"
}
