05
Mar/10
Follow iNebium on twitter

lighttpd: tips, url.redirect, url.rewrite, mod_proxy, etc...

[05 Mar 10 at 07:32:55 - 4 comment(s)]

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.


Add new comment





Notify me of follow up comments

4 Comment(s)

Miguel  -  01 Jul 2011 at 15:50:49
down  up
I think I got it with

url.redirect = (
"^/forum/(.*)$" => "http://forum.example.org/$1"
)

Miguel  -  01 Jul 2011 at 15:05:49
down  up
Hello, sorry I newbie with lighttpd and cant 'import' a redirection of apache, following the tutos.
I want all urls from example.com/forum redirected to the subdomain forum.example.com
Can you post the code?

inebium  -  07 Dec 2010 at 13:26:00
down  up
You just need to have a host for it like the following:
$HTTP["host"] == "www.host.com" {
server.document-root = "/path/to/zend/site/"
...
}

Or to redirect all the . to www, this should do:
$HTTP["host"] =~ "^\.(.*)$" {
url.redirect = ( "^/(.*)" => "http://www.%1" )
}

julian  -  07 Dec 2010 at 13:18:39
down  up
Hi there, do you know how to add [www] to a subdomain. I can access to it by using subdomain.domain.tld but no with www.subdomain.domain.tld. It seems that www is already a subdomain so i guess it can be accomplished by rewrite, any ideas will be appreciated :)

Follow the RSS feed Follow the RSS feed

Recent Posts

How to create a self signed certificate?
You need a self signed certificate for your website over https, this post is here to take you throug...
26 Apr 12
To not increase PCM value when increasing volume with pulseaudio
When you use pulseaudio and you increase the volume, it will increase the front volume but also the ...
17 Apr 12
Skype: fix crackling sound
If skype on linux gives you crackling sound and you use pulseaudio, here is the solution to fix it. ...
17 Apr 12
Install grub when booting from live CD or usb
You need to re-install grub on your drive when booting from usb or live CD. This post is made for yo...
12 Apr 12
Git: common and useful commands
I use git and literally love it but I have one problem with it, I often forget how to do things mean...
22 Mar 12

Recent Comments

vvy2000 ubuntu need root for executing this procedure.
sudo -s to get root privileges. ...
04 May 12 at 09:40:53
Danilo Cesar echo 3 | sudo tee /proc/sys/vm/drop_caches ...
16 Mar 12 at 09:32:42
inebium it's not a method, it's the constructor of the class...
05 Mar 12 at 03:22:42
Unknown method Encrypter has no return type .... ? ...
05 Mar 12 at 02:28:05
Unknown catalyst version 11.11 and still I have screen flickering, especially with something like banshee....
22 Jan 12 at 12:49:54

Categories

All (27)
Android (2)
Java (6)
Linux (18)
Misc (1)
Load Testing

Pricing

Sign Up For Free

+420 602 318 949 English / French (GMT+1)

Follow iNebium on twitter Follow us on Twitter

© iNebium 2009-2012 - All rights reserved