Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
                    )
            )
    )
}
share|improve this question

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer

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/" )
share|improve this answer
    
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 5 '13 at 9: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 5 '13 at 10:27
    
I tried exactly your example. It's sadly not working for me any ideas? –  michal.kreuzman Mar 5 '13 at 20:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.