lighttpd: tips, url.redirect, url.rewrite, mod_proxy, etc...
If you are using lighttpd or you intend to use it then you should check this post. You'll find quite a few interesting things about url-redirect and url-rewrite using respectively mod_redirect and mod_rewrite. I have added some other tips as well such as enabling compression, getting drupal to work with lighttpd or how to use mod_proxy (useful if you run a java webapp for example).
url-redirect, url-rewrite and proxy
I am not going to do a long speech here, I'll show some examples so that you can understand and use it if it answers your need.
Redirect all the www. requests to .
$HTTP["host"] =~ "^www\.(.*)$" {
url.redirect = ( "^/(.*)" => "http://%1" )
}
Redirect requests from main domain to subdomain (http://host.com -> http://sub.host.com)
$HTTP["host"] == "host.com" {
url.redirect = ( "^/(.*)" => "http://sub.host.com/$1" )
}
Proxy to a web container such as tomcat running on port 8080 but not request to statics.domain.com
$HTTP["host"] != "statics.host.com" {
$HTTP["host"] =~ "host.com$" {
url.rewrite-once = (
"^(.*)" => "/myapp/web$1"
)
proxy.server = (
"" => (
"host" => (
"host" => "127.0.0.1",
"port" => 8080
)
)
)
}
}
Enabling compression
Here are the lines you need to add to enable compression in lighttpd.
You need to load mod_compress
server.modules = (
"...",
"mod_compress"
)
Then you add the following
compress.cache-dir = "/tmp/lighttpd/"
compress.filetype = ("text/plain","text/css","text/xml","text/javascript")
I don't think these lines need any explanation.
You need to create the folder /tmp/lighttpd/ (needs to be rw by the user running lighttpd obviously)
mkdir /tmp/lighttpd/
Having a site running with drupal on lighttpd
I had to host a website built with drupal not long time ago. Here is how to proceed:
$HTTP["host"] == "host.com" {
server.document-root = "/path/to/drupal/site/"
dir-listing.activate = "disable"
magnet.attract-physical-path-to = ("/etc/lighttpd/drupal.lua")
}
You've noticed the use of a drupal.lua so here is the file: download drupal.lua. That's it, you don't need to do anything more than that.
Zend website on lighttpd
Other special case scenario. What you need:
$HTTP["host"] == "jmscs.org" {
server.document-root = "/path/to/zend/site/"
dir-listing.activate = "disable"
url.rewrite-once = (".*\.(js|ico|gif|jpg|png|css)$" => "$0", "" => "/index.php")
}
Conclusion
We've in few lines seen how to use mod_rewrite with url.rewrite, mod_redirect with url.redirect, mod_compress, mod_proxy if you host a web container such as tomcat as well as how to host a drupal or a zend website with lighttpd. Hope you'll find some of this useful.
5 comments