lighty's life

lighty developer blog

Reverse-Proxying Mod_proxy_core

I just added and commited the header rewriting support for mod_proxy_core.
$HTTP["url"] =~ "^/proxyme(/|$)" {
  proxy-core.balancer = "round-robin"
  proxy-core.protocol = "http"
  proxy-core.backends = ( "en.wikipedia.org" )
  proxy-core.rewrite-response = (
    "Location" => ( "^http://en.wikipedia.org/(.*)" => "http://127.0.0.1:1025/proxyme/$1" ),
  )
  proxy-core.rewrite-request = (
    "_uri" => ( "^/proxyme/?(.*)" => "/$1" ),
    "Host" => ( ".*" => "en.wikipedia.org" ),
 )
}
wget is happy now and follows redirect through the proxy as expected:
$ wget http://127.0.0.1:1025/proxyme/
--15:18:20--  http://127.0.0.1:1025/proxyme/
           => `index.html.1'
Connecting to 127.0.0.1:1025... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://127.0.0.1:1025/proxyme/wiki/Main_Page [following]
--15:18:20--  http://127.0.0.1:1025/proxyme/wiki/Main_Page
           => `Main_Page'
Connecting to 127.0.0.1:1025... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
...
This implements “ProxyPassReverse”:http://httpd.apache.org/docs/1.3/mod/mod_proxy.html#proxypassreverse in a very generic way. “ProxyPass”:http://httpd.apache.org/docs/1.3/mod/mod_proxy.html#proxypass is the same as the Host: rewrite in the request. Everything is controlled through the URL-conditional and limits the proxying to the /proxyme/ URL.

Enable javascript to load comments.

Please note that we won't accept comments for posts older than 3 months! Also please use our bug tracker to report bugs, and our irc channel #lighttpd@freenode to chat.

« mod_proxy_core commited to svn Hash Balancing with mod_proxy_core »