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

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 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 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 Piczak Apr 27 '10 at 11:15

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.