2

My tomcat serves 2 sites

ROOT -> Main-site
/mobile -> dedicated mobile website 

I've configured lighttpd to serve as a proxy

$HTTP["host"] =~ "www.my-site.at" {
        proxy.server = ( "" => (
                        ( "host" => "127.0.0.1",
                          "port" => 8080
                        )
                ))
}

How can I tell lighttpd to use http://127.0.0.1:8080/mobile for m.my-site.at? Or do I have to configure a second tomcat and deploy the mobile site under ROOT?

Thank you

Beig
  • 121
  • 2

2 Answers2

1

How can I tell lighttpd to use http://127.0.0.1:8080/mobile for m.my-site.at?

Use lighttpd.conf proxy.header with "map-urlpath" to add the /mobile

See lighttpd mod_proxy

As an alternative to lighttpd mod_proxy, you can use lighttpd mod_ajp13 since lighttpd 1.4.59 to use the Apache jserv protocol to reach your Tomcat server.

gstrauss
  • 276
  • 1
  • 5
1

You could use url.rewrite-once to prefix all requests on m.my-site.at with /mobile:

$HTTP["host"] == "m.my-site.at" {
    url.rewrite-once = ( ".*" => "/mobile$0" )
    proxy.server = (...)
}

You might have to load mod_rewrite before mod_proxy to get this working.

The problem with rewrites like this is that the backend now sees a path that doesn't match the browsers view. The backend might try to emit paths prefixed with /mobile or do otherwise confusing stuff with relative paths. Some proxies might try to fix these paths in responses, but lighttpd does not (and you'll never catch all of them).

The real solution is to make the backend understand vhosts - i.e. handle requests different based on the hostname. If the backend cannot do that, you might want to run multiple instances, yes.

Stefan
  • 859
  • 1
  • 7
  • 18