Project

General

Profile

reverse proxy not rewriting response

Added by mathieumg about 13 years ago

This is a follow-up to my previous post: http://redmine.lighttpd.net/boards/2/topics/4067

I went ahead and compiled/installed 1.5 off the svn. Everything works fine except for the feature I needed it for.

I have a trac daemon listening on port 8000 and I want to proxy all requests matching "^http://xx.xx.xx.xx/trac(*.)" to that daemon.

Here is what it looks like in my .conf:


$HTTP["host"] == "xx.xx.xx.xx" {
$HTTP["url"] =~ "^/trac" {
proxy-core.balancer = "round-robin"
proxy-core.protocol = "http"
proxy-core.backends = ( "127.0.0.1:8000" )
proxy-core.rewrite-response = (
"Location" => ( "^http://xx\.xx\.xx\.xx/(.*)" => http://xx.xx.xx.xx/trac/$1" ),
)
proxy-core.rewrite-request = (
"_uri" => ( "^/trac/?(.*)" => "/$1" ),
"Host" => ( ".*" => "xx.xx.xx.xx" ),
)
}

xx.xx.xx.xx is the publicly accessible IP, on port 80.

Part of that works because when I browse to http://xx.xx.xx.xx/trac I see my available projects in Trac (i.e. the page served by 127.0.0.1:8000/), whereas any other path not starting with /trac shows what it is supposed to, the content from docroot.

My only issue is that links on that page point to http://xx.xx.xx.xx/projectname, whereas they are supposed to point to http://xx.xx.xx.xx/trac/projectname. If I type http://xx.xx.xx.xx/trac/projectname manually in the url bar, I get the right page from Trac (127.0.0.1:8000/projectname, that is the homepage for that project), but with all links/images/stylesheets/etc. broken and pointing to http://xx.xx.xx.xx/projectname/* instead of http://xx.xx.xx.xx/trac/projectname.

I would like to know how to remedy to that problem, judging from the reverse-proxy code from the wiki I thought I could have used it for that, but I seem unable to rewrite any link or resource (images/stylesheets/etc.).

In case it matters, all paths in the pages returned by the trac daemon are relative. (starting at /projectname)

Thank you for your help!

Edit:

This is the response I get in Firefox:


Status=OK - 200
Server=tracd/0.12.1 Python/2.5.2
Date=Fri, 04 Feb 2011 00:30:07 GMT
Cache-Control=must-revalidate
Content-Type=text/html;charset=utf-8
Content-Length=381


Replies (1)

RE: reverse proxy not rewriting response - Added by mathieumg about 13 years ago

I ended up using trac's --base-path switch to get it working.

    (1-1/1)