Bug #164
closedmod_proxy and mod_rewrite inside the same URL conditional?
Description
$HTTP["url"] =~ "^/projects/cs(.*)" { url.rewrite = ("^/projects/cs(.*)" => "$1") proxy.server = ("/" => (( "host" => "127.0.0.1", "port" => 9090 ))) }
In the case of a conditional, as above, the request is proxied but is never rewritten.
url.rewrite = ("^/projects/cs(.*)" => "$1") proxy.server = ("/" => (( "host" => "127.0.0.1", "port" => 9090 )))
In this case (no conditional), the request is rewritten and then proxied, as expected.
-- lighttpd
Files
Updated by Anonymous almost 19 years ago
I'm having this problem too. See http://forum.lighttpd.net/topic/69
-- ryan at art of mission dot com
Updated by conny over 18 years ago
I created a pair of extra testcases for "url.rewrite inside $HOST[]".
Updated by conny over 18 years ago
But wait a moment... The first case described in the ticket is a bit odd nevertheless:
You rewrite "!^/projects/csFOO" to "/FOO", after which there are two possible outcomes:
- After the rewrite we're "back at the start" so to say: the consecutive pass does NOT match the $HOSTurl specified ("/FOO" !~ ""!^/projects/cs(.*)" and therefore handled by the outside context instead (not proxied).
- Proxied requests are always handled directly after rewrites. So in this case "/FOO/" is proxied to "http://127.0.0.1:9090/FOO"
The current documentation does not specify which case is supposed to happen.
Updated by conny over 18 years ago
With neither clear documentation nor a test unit for mod_proxy available at the moment: just stick to the alternative without conditionals.
It is really confusing to say in effect "for stuff matching /FOO: proxy everything to 127.0.0.1:9090 that matches /*everything*". Huh?!
Updated by Anonymous over 18 years ago
re: using the alternative without conditionals, there is value in doing it the first way.
Say I want to serve normal html pages but all requests to /myappserver need to be redirected.
Now say that the app server wants a clean URL, e.g. instead of /myappserver/foo going to the app server it's /foo.
In apache this functionality is achieved by
RewriteRule ^myappserver/(.*)$ http://localhost:2323/$1 [P]
There are work arounds but it would be nice to map urls cleanly.
-- weeksie
Updated by jan over 17 years ago
- Status changed from Assigned to Fixed
- Resolution set to fixed
such rewrites are supported by mod-proxy-core in 1.5.0 with proxy-core.rewrite-request.
Updated by cstefkivoila almost 16 years ago
jan wrote:
such rewrites are supported by mod-proxy-core in 1.5.0 with proxy-core.rewrite-request.
Hello,
I have the same problem than above.
Indeed, I want to achieve the following Apache line with lighttpd:RewriteRule ^myappserver/(.*)$ http://localhost:2323/$1 [P]
I am currently using lighttpd 1.4.20 on a DNS-323.
It is technically difficult to upgrade my lighttpd to the 1.5.0 release.
So my question is:
"Is there a work around of this problem for a 1.4 release of lighttpd?"
Thanks in advance for your help!
Updated by stefan about 13 years ago
Hi,
here is a workaroud I used to map an web-application on http://localhost:8008/ (its contextroot wasn't changable by configuration)
to http://webserver/myapp. The idea behind this was to do the proxying and URL rewriting inside a separate lighttpd-instance
listening on a port not being port 80 (here: port 81). This separate instance is then accessed by a lighttpd instance listening on port 80 and using
mod_proxy. Here is the config I used:
# Part for proxy listening on port 80 $HTTP["url"] =~ "(^/webapp/)" { proxy.server = ( "" => ( "webapp:80" => # name ( "host" => "127.0.0.1", "port" => 81 ) ) ) } # Part for proxy listening on port 81 $SERVER["socket"] == ":81" { url.rewrite-once = ( "^/webapp/(.*)$" => "/$1" ) proxy.server = ( "" => ( "webapp:81" => # name ( "host" => "127.0.0.1", "port" => 8008 ) ) ) }
Hope this helps someone.
Updated by flynn over 8 years ago
Although I used this "double" proxy solution for many years, I searched for better solution.
Here is my new approach with lua/mod_magnet:
$HTTP["url"] =~ "^/webapp/" { magnet.attract-raw-url-to = ( "/etc/lighttpd/lua/webapp.lua" ) proxy.server = ( "" => ("webapp" => ("host" => "127.0.0.1", "port" => 8008))) }
and /etc/lighttpd/lua/webapp.lua:
lighty.env["request.uri"] = string.sub(lighty.env["request.uri"], string.len('/webapp/')) return
This is very close to the original request ...
Updated by gstrauss almost 7 years ago
- Description updated (diff)
FYI: lighttpd 1.4.46 introduces proxy.header
which performs limited URL-prefix rewriting. More info at Docs_ModProxy
Also available in: Atom