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 run glxgears at full speed and not synchronized to vertical refresh?
You normally use glxgears to check performance of your graphic card but you get the same as your mon...
15 Nov 11
catalyst 11.10 / gnome-shell still not usable
In my post about catalyst 11.9, I wrote a rant about the AMD catalyst driver which after 6 months we...
01 Nov 11
A list of useful regexp
regexp or in other words regular expression is something you have to regularly use in your applicati...
30 Oct 11
catalyst 11.9 still doesn't work with gnome-shell!
Gnome 3.0 was released on the 6th of April 2011. At the time I write this post, Gnome 3.2 has been r...
29 Sep 11
3DES Encryption in Java and DES Encryption in Java
Here is a small post with just code to do 3DES (Triple DES) and DES Encryption in Java. You can simp...
13 Nov 10

Recent Comments

Unknown catalyst version 11.11 and still I have screen flickering, especially with something like banshee....
22 Jan 12 at 12:49:54
Javin @ Java Enum Example Java7 has several feature which developer would love one of them is fork-join framework which allows...
14 Jan 12 at 05:31:40
Javin @ Java Enum Example Java7 has several feature which developer would love one of them is fork-join framework which allows...
14 Jan 12 at 05:27:47
Vijay Hi,
This is the best tutorial I've come across so far to integrate maven with Eclipse even t...
27 Dec 11 at 11:07:13
inebium export vblank_mode=1...
25 Dec 11 at 01:19:14

Categories

All (22)
Android (2)
Java (6)
Linux (14)
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