5

I'm trying to setup a reverse proxy in lighttpd, such that all requests (and only those requests) under /mobile/video is redirected to the / directory of a secondary web server. This is pretty easy in apache, but I can't for the life of me figure out how to do so in lighttpd.

$HTTP["url"] =~ "^/wsmobile/video/" {
       url.rewrite-once = ( "^/wsmobile/video/(.+)" => "/$1" )
       proxy.server = ( "" => ( ( "host" =>  "210.200.144.26", "port" => 9091 ) ) )
}

I've tried using the http["url"] directive, but lighttpd simply ignore those requests and continue to pass the full url to the secondary server, which of course chokes and throws 404s. However, if I do a global rewrite then everything gets forwarded to the secondary server, which is also not what I want.

How do I go about this task?

2

url rewrites won't work in $HTTP["url"]. However, you should be able to rewrite it globally in this manner:

url.rewrite-once = ( "^/wsmobile/video/(.*)" => "/test/" )

and then catch it with:

$HTTP["url"] =~ "^/test/" {

   # do proxy here

}

UPDATE:

Please see here: Lighttpd bug #164. Specifically, proxy-core.rewrite-request should be what you're looking for.

  • I could do that, but the proxy server accepts only urls without any directories, and I cannot rewrite everything to /<something> because then everything gets redirected to the proxy server. – futureelite7 Apr 26 '10 at 9:49
  • OK, now it's more clear. I've updated the answer a bit. – Karol J. Piczak Apr 26 '10 at 10:23
  • I did read about mod_proxy_core. However it seems to work only with lighttpd 1.5, which is still in pre-release status after 3 years with no updates. Should I go and download 1.5 prerelease and give it a shot? – futureelite7 Apr 27 '10 at 8:50
  • It probably depends on how badly you need this kind of functionality, and how much production stable your setup needs to be. I'm using 1.4.26, so I can't tell you how it behaves. And now thinking, maybe the best way out of this would be to rewrite this part on the proxy (secondary) server itself? If that's feasible. – Karol J. Piczak Apr 27 '10 at 10:54
  • And another thought - if you really need this kind of functionality without touching the second server, you can add another layer in the backend. Make a second instance of lighttpd listening on localhost (first server) and proxy your desired urls through this middle proxy, which rewrites everything for the destination proxy. I know it's not elegant (and may be too bloated), but I don't think you can achieve your goal with lighttpd 1.4.x. Rewrites take place before mod_proxy, and the request is handled from the beginning, so you can't really discern it later on. – Karol J. Piczak Apr 27 '10 at 11:15
0

This can be done with proxy.header since lighttpd v 1.4.46. See:

https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModProxy

Example for above would be:

$HTTP["url"] =~ "^/wsmobile/video/" {
proxy.header = ("map-urlpath" => ( "/wsmobile/video" => "/" ))
proxy.server = ( "" => ( ( "host" =>  "210.200.144.26", "port" => 9091 ) ) )
}

One thing I have found though is if you post something on the proxied server (say http://210.200.144.26:9091/post-a-link"), that doesn't get translated properly back to the proxy as it throws a 404 because it's looking for a http://$PROXY/post-a-link not on the server with port 9091.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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