Running Drupal under Lighttpd
There is no doubt about the popularity of Apache among all available webservers, but there is one webserver with excellent performance which started to attract very important actor in the market : Lighttpd.
Lighttpd key features are security, speed, compliance, and flexibility. It have been optimized for high performance environments, with small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more).
As a module architecture platform, drupal also known for its high memory consumed and low performance. Some tests show that it'll level up 5x performance under lighttpd than apache for the same drupal site, that's a huge improvement.
There are two issues when migrating drupal sites from apache to lighttpd.
First, clean URLs. Lighttpd doesn't support htaccess file, so you need to write the rewrite rules to the lighttpd's configure file such as lighttpd.conf. The rewrite rules under lighttpd for drupal is something like below:
url.rewrite-once = (
"^/system/test/(.*)$" => "/index.php?q=system/test/$1",
"^/search/node/(.*)$" => "/index.php?q=search/node/$1",
"^/([^.?]*)\?(.*)$" => "/index.php?q=$1&$2",
"^/([^.?]*)$" => "/index.php?q=$1",
"^/(rss.xml)$" => "/index.php?q=$1"
)
From the above, urls without the '.' notation will be treated as drupal paths and pass to drupal system, and urls with '.' notation will be treated as normal paths and not pass to drupal. So when you want to pass something with '.' notation to drupal for example 'rss.xml', you must add them to the lighttpd conf file like the last line above did.
Second, imagecache issue. Imagecache module has a different mechanism in displaying images. If you want to use imagecache in your drupal site, you must follow these steps:
1, create a new php file with the content like these:
<?php
header("Location:http://".$_SERVER['HTTP_HOST']."/?q=".substr($_SERVER['REQUEST_URI'], 1));
?>
Save it under your drupal site's scripts directory with file name rewrite404.php.
2,open your lighttpd.conf file and add this line:
server.error-handler-404 = "/scripts/rewrite404.php"
3, restart your lighttpd, test, get it.
For other settings like compression, lighttpd is much easier than apache. You can master the grammar of lighttpd's conf file if you have some programming experience.
- wilson's blog
- Login or register to post comments

