Apache 2.2 proxy and LightTPD

The server has just undergone some modifications – previously I was using Lighttpd to serve all of the content, I liked the traffic shaping features and low memory footprint that it had. But I also sorely missed the mod_rewrite functionality and mod_php that was provided by Apache.

The solution was simple. Apache 2.2.13 to serve the Dynamic PHP files and Lighttpd to serve the static files via the Apache Proxy plugin. This results in gaining all the features of Apache but only when I need them; using Lighttpd to serve static content.

The basic setup is simple. Lighttpd runs on port 81, 127.0.0.1 and Apache runs on port 80 of idontplaydarts.com, both point to the same root directory and when Apache sees a request for a file located in either wp-content or wp-includes it instructs lighttpd to handle it. My config file looks something like this.

ProxyPass /wp-content http://127.0.0.1:81/wp-content
ProxyPassReverse /wp-content http://127.0.0.1:81/wp-content

ProxyPass /wp-includes http://127.0.0.1:81/wp-includes
ProxyPassReverse /wp-includes http://127.0.0.1:81/wp-includes

The only issue at the moment is that the latest version of Apache doesn’t yet support the ProxyPassMatch directive. This would let me specify a regular expression such as *.txt to tell Apache to pass all the requests for text files to Lighttpd.

ProxyPassMatch ^(/.*\.txt)$ http://idontplaydarts.com/$1

PassProxyMatch is due to be introduced in Apache 2.2.5, we’re only Apache 2.1.3 at the moment so there is going to be a bit of a wait before I can change my configuration files and allow support for regular expressions with PassProxy.

Its worth mentioning that you can do the proxy the other way round, lighttpd front passing it to Apache but there is not much benefit and you dont get to take advantage of the nice Apache rewrite rules

Tags: , , ,

2 Responses to “Apache 2.2 proxy and LightTPD”

  1. This way for static files, both apache and lighttpd would be working.. means a static file request would use up one apache process which already has the overheads of mod_php and whatever mod_foo you have.. and in a nut shell.. the advantage of lighttpd over apache is lost. If fact you are abusing your hardware by using this setup.

    Also mod_rewrite in apache is a facility, and much more powerful methods can be achieved by mod_magnet and lua in lighttpd. I am no advocate of lighttpd. Would it not be better to have lighttpd listen on a different port on the external interface, and configure or author the web application such that all static files will be requested with that port in prefix? or if you have multiple ips on the server, use alias domains?.

    Even better would be just to use lighttpd only, and do the rewrites using magnet and lua, like on my hobby site running wordpress selectarticles.info. I got the reference from http://www.asteriosk.gr/blog/2009/02/19/installing-wp-super-cache-with-lighttpd/

  2. Phil says:

    Your totally right – Ive just tested it and i got 85ms avg response time for apache vs 88ms for lighttpd (1000 requests with 100 connections serving 128kb of data). Perhaps the way forward would be to use lighttpd on the frontend and pass the php scripts via proxy to apache?

    I moved away from using lighttpd in the first place as the mod_php was much quicker than the fast-cgi php.

Leave a Reply