Lighttpd as reverse proxy

We often recommend to set lighttpd in front of apache to handle http requests (more about ) , redirect dynamic requests to apache and handle static files by itself. I just gathered step-by-step instruction how to do that in 10 minutes, as it may be not so obvious.

  • Of course you need lighttpd by itself, it’s available on
  • You may want pcre-devel packet, which allows to use regular expressions in lighttpd.conf. For CentOS boxes we just run
  • Take sample config file and put to
  • Create directory to store log files, e.g. . Despite it looks simple, lighttpd may just die trying to create files in non-existing directory.
  • Set to point to actual directory with web documents
  • Uncomment next lines in lighttpd.conf

    mod_status is useful to show additional information from lighttpd
    mod_auth to protect mod_status from unauthorized access 🙂
    and mod_proxy is proxy by itself

  • to enable status uncomment or add to lighttpd.conf
  • to protect access to /server-status put next lines to lighttpd.conf

    It enables htpasswd file based authentication, you can just manage this file with htpasswd utility from apache.

  • and finally make changes related to proxy
    1. Move apache from 80 port to another, e.g. 8080 or pick your own.
    You need to change and directives in httpd.cong
    and meantime set , as we want apache only handling dynamic pages.
    2. put next lines to lighttpd.conf:

    This actually directs lighttpd to redirect all requests, besides one ending (you can add your own static pages), to apache listening on 8080 port
  • Final step to add lighttpd to list of services (actual only for RedHat / CentOS)

    fix path

    and add script to autostart

That’s all. For complex apache setups and VirtualHosts it may be trickier, but work just fine for simple cases.

Share this post

Comments (28)

  • emil

    This is interesting – we actually do the opposite 🙂 – apache as reverse proxy + mod_security + static file handling in front of the lighttpd/fcgi.

    June 17, 2008 at 9:08 pm
  • mike

    ew. you should look at nginx. ncache (based on nginx) if you need a proxy that -stores- a cache of the content.

    nginx is the most efficient proxy out there, hands down. once you try it you -will not- go back.

    June 17, 2008 at 9:38 pm
  • Mat

    Here, we use “HAproxy” in front for reverse proxy and load balancing.
    It’s VERY fast to parse HTTP requests and it handle failover.
    It’s possible to do the same thing with it : send all static content requests to lighttpd and all dynamic content to apache.

    If you have a lot of traffic, you should look at this 🙂

    June 17, 2008 at 10:47 pm
  • frederic

    we do not handle static files at all 😉 we completely rely on amazon S3 for that and lighttpd just handle the dynamic pages
    to solve the ETAG, expiration of new static files, we use either a revision number in the URLs or an SVN tag

    we also decide to compress all the files we put on amazon S3 as gzip mode in mainly supported by all browsers

    June 18, 2008 at 12:13 am
  • Saiyine

    What do you mean with compress all the files? They’re just compressed with gzip and then decompressed on the fly by the web browser???

    For example, having file.txt, do you mean compressing it to file.txt.gz and be able to access ? I’d love to know how to do it!

    Or is just enabling the on the fly server compression like mod_deflate/mod_gzip, wich is forbidden for it’s cpu usage by most hostings?

    June 18, 2008 at 1:19 am
  • Ira

    Isn’t it better to use a cache/accelerator dedicated product like squid as a front-end instead of lighttpd?

    June 18, 2008 at 3:29 am
  • jo

    use nginx for this.
    it is better then lighttpd

    now 2 million hosts use this server (month ago — 1 million…) enjoy

    ( )

    June 18, 2008 at 4:25 am
  • JohnShep

    Isn’t Lighttpd better suited as a replacement for Apache rather than a front end to it ? To serve static content I recommend using thttpd, it is very fast, very stable and very light on resources.

    June 18, 2008 at 6:07 am
  • jo June 18, 2008 at 6:37 am
  • Alex Forrow

    If you wish to give the impression of a single domain surely using Squid in reverse proxy mode is the simplest? Get one httpd to serve both static and dynamic, but get squid to cache the static?
    At we have a dedicated domain for static content, which is served by lighttpd. Apache then hosts the dynamic.

    sent from: [FID179790]