2

I am using lighttpd and tomcat running behind. I want lighttpd to handle all static files like images / css. Here is my config :

$HTTP["host"] =~ "www.example.com" {
    alias.url = ( "/images_deal/" => "/home/deal/projects/deal/images/" )   
    alias.url += ( "/statics_deal/" => "/home/deal/workspace2/dolo/statics/" )  
    proxy.server = ( "" =>                 
        ( "tomcat" =>
            (
                "host" => "127.0.0.1",
                "port" => 8080,
                "fix-redirects" => 1
             )
        )
    )
}

server.modules = (  "mod_access",  "mod_alias",  "mod_redirect",  "mod_rewrite",)

The probleme is that I can't acces images on url like http://www.example.com/images_deal/img.png

I write a new lighthttpd configuration that enables access to static files, but the problem now is that I can't access my tomcat context directly, I mean : rewrite all request www.example.com to www.example.com/dolo/ before passing it to tomcat (because tomcat has more than one context. New config

    alias.url = (
        "/images_deal" => "/home/deal/projects/deal/images/",
        "/statics_deal/"      => "/home/deal/workspace2/dolo/statics/",
    )
  $HTTP["url"] !~ "^(/statics_deal/|/images_deal/)" {
   url.rewrite-once = ( "^/(.*)" => "/dolo/$1", )      
   proxy.server = ( "" =>
                 ( "tomcat" =>
                   (
                     "host" => "127.0.0.1",
                     "port" => 8080,
                     "fix-redirects" => 1
                   )
                 )
              )
  }
}
badrux
  • 33
  • 5
  • The modules need to be defined above their actual use. Also, every downloadable file extension has to have a mime-type, make sure that .png is defined. It may not be by default. – Zdenek Jul 21 '16 at 19:16

1 Answers1

0

Update: lighttpd 1.4.59 has lighttpd mod_ajp13 as an option to connect to a backend Tomcat, as an alternative to lighttpd mod_proxy.

For your config shared above, I think this would work for you:

url.rewrite-once = ( 
  "^/(?:statics_deal|images_deal|dolo)/" => "",
  "^/(.*)" => "/dolo/$1"
)
alias.url = ( 
  "/images_deal/"  => "/home/deal/projects/deal/images/",
  "/statics_deal/" => "/home/deal/workspace2/dolo/statics/",
)   
proxy.server = ( 
   "/dolo/" => ( "tomcat" =>
                   ( 
                     "host" => "127.0.0.1",
                     "port" => 8080, 
                     "fix-redirects" => 1
                   )
               )
) 
gstrauss
  • 2,091
  • 1
  • 12
  • 16