Reduce Apache's Load With lighttpd On Debian Etch

Want to support HowtoForge? Become a subscriber!
 
Submitted by axman (Contact Author) (Forums) on Thu, 2008-02-07 12:32. :: Debian | Apache | Lighttpd

Reduce Apache's Load With lighttpd On Debian Etch

Lighttpd, sometimes pronounced "Lighty", is a lightweight HTTP server that can help alleviate Apache's load by serving static content. Since Lighttpd uses less resources per request than Apache, it generally serves most static content faster than Apache. This tutorial shows how to install Lighttpd behind Apache via Apache´s proxy module.

No guarantee that this will work for you!

 

1 Requirements

To install such a system you will need the following:

 

2 Setting up lighttpd

Once Lighttpd is installed, you'll have to modify the configuration file to use it

vi /etc/lighttpd/lighttpd.conf

#bind to port (Default: 80)
server.port = 81

# bind to localhost (recommended for proxy behind Apache, otherwise comment this out for all) 
server.bind = "localhost"
This is not a full listing of the configuration file, but rather a highlight of the most important parts. Notice that we've set the server port to 81. By doing this, we're making sure it doesn't clash with Apache listening on port 80. If you wanted to let Lighttpd power your entire site instead of Apache, you can set this to port 80, or comment it out to accept the default.

Then we restart Lighttpd:

/etc/init.d/lighttpd restart

 

3 Setting up Apache's proxy

To let Apache take the output of Lighttpd on port 81 and map it to your website, you'll need to make sure the Proxy module of Apache is loaded.
Using the Perfect Setup tutorial this module will either be there already but not activated.

a2enmod proxy_http
a2enmod proxy_connect

If you are using virtual hosting, you will want to use the following code to set up a proxy between the applicable directives:

ProxyRequests Off
ProxyPreserveHost On
ProxyPass /media http://0.0.0.0:81/
ProxyPassReverse / http://0.0.0.0:81/

Then we restart Apache:

/etc/init.d/apache2 reload

 

4 Final notice

In the above example, Lighttpd will serve up your media folder, leaving Apache to do the rest. Set this to any folder that has static content in it and Lighttpd will serve it, instead of Apache. Another good use of Lighttpd would be to serve up multimedia files, taking the load off of Apache. The increase of performance you'll gain is dependent on many factors. If you only have Lighttpd serve up your images, it probably won't help too much. You can put all of your static content, including HTML and PDF files, images, and movies in a folder called /static and then set the ProxyPass variable to that for a slightly better performance.

The increase of performance you've gained so far with Lighttpd is not phenomenal, but helps to increase the website performance and reduces the load on your server.

 

5 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by charles (registered user) on Sun, 2008-02-10 19:20.

i would do this in the following way:

- change the apache port to 81

- install lighttpd and bind it to port 82

- install <a href="http://www.apsis.ch/pound/index_html">pound</a> and bind it to port 80

pound can act very efficiently as a reverse proxy and pass on the requests to apache and lighttpd. 

Submitted by jadonohu (registered user) on Fri, 2008-02-08 00:47.

The increase of performance you've gained so far with Lighttpd is not phenomenal, but helps to increase the website performance and reduces the load on your server.

I don't understand why a proxy/proxyreverse for a given request would put any less load on apache than just serving the static content directly.

To my (admittedly uneducated) mind, it seems that this proxy solution would be at least as much work for apache, if not more.

Submitted by Anonymous (not registered) on Mon, 2008-10-13 20:46.

I agree, having Lighttpd reverse proxy requests for dynamic content to Apache makes more sense.

 With Lighttpd in front the more memory hungry Apache would not be wasted serving static content.