X-Sendfile's new friend: X-Rewrite-* 4
Today on IRC I got a question on:
<b>Fobax</b> can you x-send-file from fast-cgi to a proxy request?
Or asked in another way ?
Can you use a mod_proxy_core backend to rewrite a URL or a Host header ?
After 30 minutes of coding … Yes, you can …
Some tweaking and here and there and we had:
proxy-core.allow-x-rewrite = "enable"
which allows you to send:
HTTP/1.0 200 OK X-Rewrite-URI: /pi.php X-Rewrite-Host: www.foobar.com
as response and lighty will replace both values and the original request and start the whole request from scratch. Here I rewrite the incoming request to use another internal Host and a new URI.
What is this good for ?
- rewriting http://user.example.org/ to http://xample.org/~user/
- denying access to host with unwanted content based on the Hostname
- filtering in general
Do you have other examples ?
Trackbacks
Use the following link to trackback from your own site:
http://blog.lighttpd.net/articles/trackback/1824
-
I just uploaded the 3rd pre-release of lighttpd 1.4.12: http://www.lighttpd.net/download/lighttpd-1.4.12-20060724-0947.tar.gz This pre-release should work on most platforms and it mainly got improvements for our mongrel users. A small test has sho...
$HTTP["host"] == "external.com" { fastcgi.server = ( ".php" => ("socket" => "/tmp/php-fcgi.socket", proxy-core.allow-x-rewrite = "enable" )) url.rewrite = ( "(.*)" => "/rewrite.php?$1") } $HTTP["host"] == "internal1.external.com" { proxy.server = ( "" => ( "host" => "192.168.1.1", "port" => 80 )) } $HTTP["host"] == "internal2.external.com" { proxy.server = ( "" => ( "host" => "192.168.1.2", "port" => 80 )) }$HTTP["host"] == "external.com" { $HTTP["url"] !~ "\.php$" { proxy-core.protocol = "fastcgi" proxy-core.backends = ( "/tmp/php-fcgi.socket" ) proxy-core.allow-x-rewrite = "enable" proxy-core.rewrite-request = ( "_uri" => ( "(.*)" => "/rewrite.php?$1")) } } $HTTP["host"] == "internal1.external.com" { proxy-core.backends = ( "192.168.1.1" ) } $HTTP["host"] == "internal2.external.com" { proxy-core.backends = ( "192.168.1.2" ) }