lighttpd and apache mod_proxy

Tags: 

Playing a little bit with lighttpd and it turns out to be good. Unfortunately, OpenSuse does not have lighttpd comes with the packages so I have to compiled it myself. There's source rpm available on their site, so it's not that hard. To get started, just edit the configuration file, you can named it anything but let's put it as lighttpd.conf. The documentation is not really verbose about the configuration but you can get a lot of samples out there. Few things that I want to put a note is the conditional part. Sort of like this:-

$HTTP["host"] == "www.k4ml.com" {
  server.document-root = "/home/kamal/public_html/project/kxblog/trunk/www/"
  server.errorlog = "/home/kamal/lighttpd/lighttpd-error.log"
  accesslog.filename = "/home/kamal/lighttpd/access_log"

server.error-handler-404 = "/index.php"

fastcgi.server = ( ".php" => (( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/srv/www/cgi-bin/php", "bin-environment" => ( "PHP_FCGI_CHILDREN" => "4", "PHP_FCGI_MAX_REQUESTS" => "10" ) )) )

}

Most people use this feature for a virtual hosting and it really handy for that purpose. It allows me for unlimited document_root within my home directory for every sub domain that I have. And also note php-fastcgi, since lighttpd running as my userid I don't need suExec anymore.

To start lighty, just type:-

$ lighttpd -f lighttpd.conf

If nothing comes out, everything should be ok. To verify it:-

$ curl -v http://www.k4ml.com:8139/ | head
* About to connect() to www.k4ml.com port 8139
*   Trying 207.7.108.53... connected
* Connected to www.k4ml.com (207.7.108.53) port 8139

GET / HTTP/1.1 User-Agent: curl/7.14.0 (i686-suse-linux) libcurl/7.14.0 OpenSSL/0.9.7g zlib/1.2.3 Host: www.k4ml.com Accept: /

< Date: Fri, 06 Jan 2006 08:05:58 GMT < Server: lighttpd | k4ml

The server was set to run at port 8139 (you can choose any port) since port 80 already used by apache. Now the fun part. To enable user accessing the site using only www.k4ml.com and still be served by lighttpd, we can proxy the request through apache. If mod_proxy available, just put this in the virtual host context:-

ProxyRequests Off
ProxyPreserveHost On

Order deny,allow
Allow from all

ProxyPass / http://www.k4ml.com:8139/
ProxyPassReverse / http://www.k4ml.com:8139/

Now all request to www.k4ml.com will be passed to www.k4ml.com:8139, the lighttpd server by apache. By patching the drupal's code a little bit, I'm able to get drupal's clean url to work without using mod_rewrite anymore !. However, some problem with dokuwiki forced me to revert this site back to apache. Based on this litle experimentation, there's a possibility that I would turn up to lighttpd in the future.

Main reference - Lighttpd, the painless way

1 comment

1.  andrea (16 June, 2009 - 13:43) says:

thanks!
this part was fundamental, it was not mentioned in any other tutorial I found:

Order deny,allow
Allow from all

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options