Lighttpd Cheat Sheet
Lighttpd (Lightweight HTTP Server) Cheat Sheet:
- Installation:
- Linux: Use the package manager (e.g., apt-get, yum) to install lighttpd.
- Windows: Download the Windows binary from the official website and run the installer.
- Configuration:
- Main configuration file: /etc/lighttpd/lighttpd.conf (Linux) or lighttpd.conf (Windows).
- Use a text editor to modify the configuration file.
- Common configuration options:
- server.document-root: Set the document root directory.
- server.port: Set the port number to listen on.
- server.username and server.groupname: Set the user and group for running the server.
- server.modules: Enable or disable specific modules.
- mimetype.assign: Define MIME types for file extensions.
- accesslog.filename: Set the access log file path.
- server.errorlog: Set the error log file path.
- Starting and stopping the server:
- Linux: Use the service command (e.g., service lighttpd start/stop/restart).
- Windows: Use the Lighttpd control panel or start/stop the service from the Services console.
- Virtual Hosts:
- Enable virtual hosts by uncommenting the “include_shell” line in the configuration file.
- Create separate configuration files for each virtual host (e.g., mysite.conf).
- Add the necessary configurations for each virtual host, such as server.document-root and server.name.
- URL Rewriting:
- Enable mod_rewrite by adding “mod_rewrite” to the server.modules configuration.
- Use the “url.rewrite” option to define rewrite rules.
Example rewrite rule:
url.rewrite = ( "^/old-page$" => "/new-page", "^/category/(.*)$" => "/index.php?category=$1" )
- SSL/TLS Configuration:
- Enable mod_openssl by adding “mod_openssl” to the server.modules configuration.
- Generate or obtain an SSL certificate and key.
- Configure SSL options in the server configuration, such as ssl.pemfile and ssl.ca-file.
- FastCGI Configuration:
- Enable mod_fastcgi by adding “mod_fastcgi” to the server.modules configuration.
- Configure FastCGI options, such as fastcgi.server and fastcgi.map-extensions.
- Access Control:
- Use the “url.access-deny” option to deny access to specific URLs or file extensions.
- Use the “url.access-allow” option to allow access to specific URLs or file extensions.
Example access control rules:
url.access-deny = ( "~", ".inc" ) url.access-allow = ( "/public" )
- Caching:
- Enable mod_expire by adding “mod_expire” to the server.modules configuration.
- Use the “expire.url” option to define caching rules based on URL patterns.
Example caching rule:
expire.url = ( "/static/" => "access plus 1 year", "/images/" => "access plus 1 month" )
- Logging:
- Access logs: Enable access logging by setting accesslog.filename in the configuration file.
- Error logs: Set server.errorlog to specify the error log file path.
Remember to restart the server after making any changes to the configuration file for the changes to take effect.