lighttpd

From Gentoo Wiki
Jump to: navigation, search

Resources

lighttpd is a fast and lightweight web server.

Installation

USE flags

USE flags for www-servers/lighttpd Lightweight high-performance web server

bzip2 Use the bzlib compression library global
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally global
fam Enable FAM (File Alteration Monitor) support global
gdbm Add support for sys-libs/gdbm (GNU database libraries) global
ipv6 Add support for IP version 6 global
kerberos Add kerberos support global
ldap Add LDAP support (Lightweight Directory Access Protocol) global
libev Enable fdevent handler local
libressl Use dev-libs/libressl as SSL provider (might need ssl USE flag), packages should not depend on this USE flag global
lua Enable Lua scripting support global
minimal Install a very minimal build (disables, for example, plugins, fonts, most drivers, non-critical features) global
mmap Use mmap with files owned by lighttpd. This is a dangerous option as it may allow local users to trigger SIGBUS crashes. local
mysql Add mySQL Database support global
pcre Add support for Perl Compatible Regular Expressions global
php Include support for the PHP language global
rrdtool Enable rrdtool support via mod_rrdtool local
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur global
ssl Add support for Secure Socket Layer connections global
test Workaround to pull in packages needed to run with FEATURES=test. Portage-2.1.2 handles this internally, so don't set it in make.conf/package.use anymore global
webdav Enable webdav properties local
xattr Add support for extended attributes (filesystem-stored metadata) global
zlib Add support for zlib (de)compression global

Emerge

Install www-servers/lighttpd:

root #emerge --ask www-servers/lighttpd

Configuration

The lighttpd configuration is handled by /etc/lighttpd/lighttpd.conf. The first example shows a single-site access, with SSL and no dynamic capabilities (such as PHP).

FILE /etc/lighttpd/lighttpd.confExample 1
$SERVER["socket"] == "192.0.2.10:443" {
  server.name = "www.genfic.com"
  server.document-root = "/var/www/www.genfic.com/"
  server.errorlog = "/var/log/lighttpd/http_error.log"
  accesslog.filename = "/var/log/lighttpd/http_access.log"
  ## SSL Configuration
  ssl.engine = "enable"
  ssl.pemfile = "/etc/ssl/lighttpd-ssl.pem"
  ssl.ca-file = "/etc/ssl/certs/ca-certificate.crt"
  # SSL options
  ssl.use-sslv2 = "disable"
  ssl.cipher-list = "TLSv1+HIGH !SSLv2 RC4+MEDIUM !aNULL !eNULL !3DES @STRENGTH"
}

To enable additional functionalities configure needed modules in /etc/lighttpd/lighttpd.conf. For instance, to enable PHP using the FastCGI processor:

FILE /etc/lighttpd/lighttpd.confExample 2 - Enabling PHP support
...
include "mod_fastcgi.conf"
...

IP access lists

This third example shows how to allow access to a particular site /server-status only to certain IP addresses. To allow using service status on the 198.51.100.1 and 127.0.0.1 addresses, set the following lines in the lighttpd.conf file:

FILE /etc/lighttpd/lighttpd.confExample 3 - Enabling and configuring an IP access lists for /server-status page
# enable access module
server.modules = {
  ...
  "mod_access",
}
...
# enable server-status page globally
status.status-url  = "/server-status"

...
# restrict access to server-status to listed IP hosts
$HTTP["remoteip"] !~ "198.51.100.1|127.0.0.1" {
      url.access-deny = ( "/server-status" )
}

Start up

In order for the lighttpd service to start automatically it must be properly added to the init handler program. Gentoo has two main init handler programs: OpenRC and Systemd.

OpenRC

With OpenRC use the rc-update command:

root #rc-update add lighttpd default

systemd

With systemd use the systemctl command:

root #systemctl enable lighttpd.service

Troubleshooting

Verifying /etc/lighttpd/lighttpd.conf configuration file with lighttpd-angel, it will return the exit code 0, if everything is configured properly:

root #lighttpd-angel -t -f /etc/lighttpd/lighttpd.conf
Syntax OK
lighttpd-angel.c.140: child (pid=32491) exited normally with exitcode: 0

If the configuration file has errors, it will print it to stdout, like in the example below:

root #lighttpd-angel -t -f /etc/lighttpd/lighttpd.conf
2012-09-02 12:52:08: (plugin.c.131) Cannot load plugin mod_fastcgi more than once, please fix your config
2012-09-02 12:52:08: (network.c.379) can't bind to port: 192.168.0.1 80 Address already in use 
lighttpd-angel.c.140: child (pid=32139) exited normally with exitcode: 255

See also

  • Apache — an efficient, extensible web server. It is one of the most popular web servers used the Internet.
  • Nginx — a robust, small, high performance web server and reverse proxy server.

External resources

http://redmine.lighttpd.net/projects/lighttpd/wiki - The Lighttpd wiki.