Lighttpd With Mod_Proxy And Mongrel Problem

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

proxy.balance = "fair"

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

The problem is that ALL request are forwarded to mongrel, even static content, css, js, and images. If I try replacing proxy.server = "/" with proxy.server = ".fcgi" the rails application does not work. Any ideas on how we can serve static html, images, js, css from Lighttpd, but push ruby on rails requests to the mongrel cluster?

3 Replies

I must admit I've never used Lighttpd but I often do the same thing with nginx (You might want to look at it if you haven't had specific reasons for lighttpd?) and it seems the config is much the same. Basically you can:

* - Set up a specific directory or subdomain and have it serve that as static

(eg. Make a folder "static", then use "/static/" in place of "/" and put all images, etc. in there)

- Match patterns on a URL

(eg. "Only proxy *.html" or "proxy everything but *.jpg and *.png" for images):

<url url=""></url>

- Tell it to check for a file on disk that matches the URL and only ask the proxy if you can't find one.

(Sorry, couldn't find an example of this for Lighttpd)</list> 

All are safe options, which one is best will depend on your specific setup, you can probably see the pros and cons for your scenario already.


Thanks fort the reply. Somebody actually gave me the solution in the lighttpd forums. I will post it here, hopefully it helps somebody else one day.

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

Strictly speaking, that's still not correct. What you're doing is telling lighttpd to forward all requests except for those that end in a few static extensions. That doesn't handle unexpected cases; for example, that would redirect for a file called "index.htm" since "htm" isn't in your list of extensions.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct