Lighttpd: Installation and configuration of an Apache alternative
Introduction
LigHTTPd (or “lighty”) is a secure, fast, and flexible HTTP server.
Its speed comes from having a smaller memory footprint than other HTTP servers, as well as intelligent CPU load management.
Many languages like PHP, Perl, Ruby, and Python are supported via FastCGI.
The main disadvantage of LigHTTPd is that it has only one configuration file and doesn’t support .htaccess files (though there are alternatives): directives must be in the configuration file. This is also an advantage, as the server administrator only has one file to manage.
In April 2007, LigHTTPd entered the Top 5 of the most widely used web servers.
Installation
To install it, it’s simple:
|
|
Installation of the PHP module
|
|
To enable it, do:
|
|
We’ll also add these few lines at the end of the configuration file:
|
|
Then reload Lighttpd:
|
|
Configuration
Forcing SSL redirections
It can be useful to redirect part of your traffic to SSL. This is my case for mediawiki which doesn’t take SSL into account during authentication (or I don’t know how to do it, but it doesn’t matter, the idea here is to have a small exercise):
|
|
Here I’m telling it:
- Everything that comes in on port 80
- From any host
- If it arrives on a page containing ‘Connexion&returnto’
- Then it is redirected to https at the same location as the previous one
Differentiating logs
For example, I want to differentiate the logs of my blog as well as the rest of my domain and my wiki to be able to process them correctly with awstats. Here’s how to do it:
|
|
Blocking access to your site via Internet Explorer
It is possible to block access to all kinds of browsers. If like me, you’re not friends with IE (which breaks your PNGs in version 6, doesn’t respect standards, breaks CSS, etc.), it might be useful to block it and kindly indicate to the user to download Firefox as soon as possible.
I did it under Apache and here I couldn’t pass up the opportunity to do it for Lighttpd, so here’s the solution:
|
|
All that’s left is to create the ie.html file and put your nice text in it (you can also make a simple text file). Here’s what I use (/var/www/ie.html
):
|
|
Access restriction by login and password
Htaccess files don’t exist in Lighttpd, but there is an equivalent. Check before you start that the mod_auth module is loaded. First, we’ll generate (with -c for the first time, like htaccess) a file containing the credentials for authorization to view a particular site:
|
|
Here I’m creating the user deimos. The realm (here ‘Authorized users only’) will allow us to differentiate between the different login/password files we’ll have since we can only specify one for the entire server.
Then add these lines to the global lighttpd configuration:
|
|
Then I add protection at the location I’m interested in:
|
|
Restart lighty and you’re done.
Adding compression
To speed up the display of your website, it’s recommended to enable compression. By default, not enough elements are compressed, so you’ll need to define more in the standard configuration. Note: Enabling compression will put a bit more load on your server’s CPU/RAM.
Edit your lighty configuration to configure the compress module:
|
|
PHP5 compression will save us precious seconds on page display. To enable it, edit the following file and set the parameter to “on”:
|
|
Then restart your web server for the configuration to be applied.
FAQ
Symbol `FamErrlist’ has different size in shared object, consider re-linking
If you get this kind of error when restarting Lighttpd:
Stopping web server: lighttpd.
Starting web server: lighttpd/usr/sbin/lighttpd: Symbol `FamErrlist' has different size in shared object, consider re-linking
2010-08-20 21:58:02: (network.c.345) can't bind to port: :: 80 Address already in use
failed!
This is due to a bug with IPv6 on Debian. To solve the problem, you need to install libfam0 which also causes these kinds of bugs:
|
|
and in the Lighttpd configuration, configure these lines like this:
#include_shell "/usr/share/lighttpd/use-ipv6.pl"
server.socket = "[::]"
All that’s left is to restart Lighttpd :-)
sockets disabled, connection limit reached
If your server stops abruptly and you get this kind of message:
2011-05-06 14:18:24: (server.c.1398) [note] sockets disabled, connection limit reached
2011-05-06 14:19:27: (server.c.1512) server stopped by UID = 0 PID = 19214
It’s simply that you’ve exceeded the maximum number of file descriptors. You just need to increase the current value. To find out which one is currently applied (default 1024), just run this command:
|
|
Here it is limited to 1024. To increase this value, edit the lighty conf file and increase the value:
server.max-fds = 2048
All that’s left is to restart lighty.
backend is overloaded; we’ll disable it for 1 seconds and send the request to another backend instead: reconnects
If you get this kind of message with a nice 500 error:
2011-05-09 09:06:07: (mod_fastcgi.c.2764) fcgi-server re-enabled: 0 /tmp/php.socket
2011-05-09 09:06:07: (mod_fastcgi.c.2764) fcgi-server re-enabled: 0 /tmp/php.socket
2011-05-09 09:06:07: (mod_fastcgi.c.2764) fcgi-server re-enabled: 0 /tmp/php.socket
2011-05-09 09:06:07: (mod_fastcgi.c.2764) fcgi-server re-enabled: 0 /tmp/php.socket
2011-05-09 09:06:10: (mod_fastcgi.c.3001) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 521
2011-05-09 09:06:10: (mod_fastcgi.c.3001) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 1 load: 521
2011-05-09 09:06:10: (mod_fastcgi.c.3001) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 2 load: 521
2011-05-09 09:06:10: (mod_fastcgi.c.3001) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 3 load: 521
It’s because your fastcgi limits have been exceeded. To solve the problem, here’s the configuration to modify:
fastcgi.server = (
".php" => ((
"bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket",
"max-procs" => 10,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "10",
"PHP_FCGI_MAX_REQUESTS" => "500"
)
)
))
Then adjust the lines above to accommodate the maximum number of clients you want, as well as the number of instances. You can test your new configuration with the “ab” command.
More info on this page: https://redmine.lighttpd.net/wiki/1/Docs:PerformanceFastCGI
Resources
- Documentation on installing Lighttpd With PHP5 And MySQL Support
- Documentation on reducing Apache’s load with lighttpd
- Optimizing Lighttpd server load
- https://redmine.lighttpd.net/wiki/lighttpd/Docs
- https://redmine.lighttpd.net/wiki/lighttpd/Docs:ConfigurationOptions
- Installing Lighttpd With PHP5 And MySQL Support On Debian Lenny
Last updated 10 May 2011, 11:05 CEST.