1

How can I configure Lighttpd to serve static content on specified URL address (eg. www.my-domain.com/static) from specified directory (e.g. /var/www/my-domain/static) ?

Rest of requests must be passed to tomcat container.

Actually I pass all requests to tomcat (see snippet below). I can't get it to work. So if it's not possible - NO is also answer for me. At least I will stop trying.

$HTTP["host"] =~ "www.my-domain.com" {
    proxy.server = ("" => (
                    "tomcat" => (
                            "host" => "127.0.0.1",
                            "port" => 8080,
                            "fix-redirects" => 1
                    )
            )
    )
}
the-wabbit
  • 40,737
  • 13
  • 111
  • 174
michal.kreuzman
  • 335
  • 3
  • 7

2 Answers2

3

You have to "disable" the proxy on static files (i.e. enable it only on other files):

$HTTP["host"] =~ "www.my-domain.com" {
    server.document-root = "/var/www/my-domain"
    $HTTP["url"] !~ "^/static" {
        proxy.server = ("" => ( "tomcat" => (
            "host" => "127.0.0.1",
            "port" => 8080,
            "fix-redirects" => 1
        ) ) )
    }
}

Also try debug.log-request-handling = "enable" and check error.log, also see http://redmine.lighttpd.net/projects/lighttpd/wiki/DebugVariables

Stefan
  • 859
  • 1
  • 7
  • 18
0

You just need a new rule to handle static content:

$HTTP["host"] =~ "www.my-domain.com" {
    $HTTP["url"] =~ "^/static" {
        server.document-root = "/var/www/my-domain/static"
    }

    proxy.server = ("" => (
                    "tomcat" => (
                            "host" => "127.0.0.1",
                            "port" => 8080,
                            "fix-redirects" => 1
                    )
            )
    )
}

Edit:

You could try with an alias:

alias.url = ( "/static" => "/var/www/my-domain/static/" )
j0k
  • 411
  • 9
  • 16
  • Hi, thanks for reply. This one I actually tried but it's not working (don't know why). I'm getting 404 for my static content. Is this solution works for you in practice? I'm using Lighttpd 1.4.28. What's your version? – michal.kreuzman Mar 05 '13 at 09:43
  • I use same version. I didn't test it, I usually forward static content to a dedicated webserver (like nginx) using proxy.server – j0k Mar 05 '13 at 10:27
  • I tried exactly your example. It's sadly not working for me any ideas? – michal.kreuzman Mar 05 '13 at 20:19