Project

General

Profile

lighttpd with mod_proxy and mongrel

Added by JustinK101 over 5 years ago

We are using Lighttpd 1.4.28 along with mod_proxy to push requests to a mongrel cluster. Our configuration is:

proxy.balance = "fair" 

$HTTP["host"] == "www.mydomain.com" {
  proxy.server  = ("/" => (
                              ("host" => "127.0.0.1", "port" => 3001),
                                ("host" => "127.0.0.1", "port" => 3002),
                                ("host" => "127.0.0.1", "port" => 3003),
                                ("host" => "127.0.0.1", "port" => 3004)
                          ))
}

The problem is that ALL request are forwarded to mongrel, even static content, css, js, and images. Any ideas on how we can serve static html, images, js, css from lighttpd (we want to use lighttpd gzip and expire headers), but still push ruby on rails requests to the mongrel cluster? Thanks.


Replies (4)

RE: lighttpd with mod_proxy and mongrel - Added by radzio over 5 years ago

Use regex with $HTTP["url"]:

$HTTP["url"] =~ "\.(rb|ruby|whatever_extension_you_need)$" {
        proxy.server = .....
}

RE: lighttpd with mod_proxy and mongrel - Added by JustinK101 over 5 years ago

Radzio,

Instead of doing what I need, can you provide how I would send everything to the proxy server except: .css, .js, .html, .png, .jpg, .gif, .ico, .swf. Thanks.

RE: lighttpd with mod_proxy and mongrel - Added by radzio over 5 years ago

Sure.

$HTTP["url"] !~ "\.(css|js|html|png|jpg|gif|ico|swf)$" {
        proxy.server = ...
}

It will proxy everything except these extensions.

RE: lighttpd with mod_proxy and mongrel - Added by JustinK101 over 5 years ago

Radzio,

Thanks very much for the help. That worked perfectly! Here is the final block of code, hopefully helps others.

$HTTP["host"] == "www.mydomain.com" {
        $HTTP["url"] !~ "\.(css|js|html|png|jpg|gif|ico|swf)$" {
                proxy.server  = ("" => (
                                        ("host" => "127.0.0.1", "port" => 3002),
                                        ("host" => "127.0.0.1", "port" => 3003),
                                        ("host" => "127.0.0.1", "port" => 3004),
                                        ("host" => "127.0.0.1", "port" => 3005)
                                ))
        }
}
    (1-4/4)