Project

General

Profile

Bug #164

mod_proxy and mod_rewrite inside the same URL conditional?

Added by Anonymous over 13 years ago. Updated about 1 year ago.

Status:
Fixed
Priority:
Normal
Assignee:
-
Category:
mod_rewrite
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Missing in 1.5.x:

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

lighttpd-mod-rewrite-host-test.patch (2.82 KB) lighttpd-mod-rewrite-host-test.patch "url.rewrite" is deprecated: use url.rewrite-once instead conny, 2006-02-09 11:37

History

#1

Updated by jan over 13 years ago

  • Status changed from New to Assigned
#2

Updated by Anonymous almost 13 years ago

I'm having this problem too. See http://forum.lighttpd.net/topic/69

-- ryan at art of mission dot com

#3

Updated by conny almost 13 years ago

I created a pair of extra testcases for "url.rewrite inside $HOST[]".

#4

Updated by conny almost 13 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:

  1. 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).
  1. 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.

#5

Updated by conny almost 13 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?!

#6

Updated by Anonymous over 12 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

#7

Updated by jan over 11 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.

#8

Updated by cstefkivoila almost 10 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!

#9

Updated by stefan about 7 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.

#10

Updated by flynn over 2 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 ...

#11

Updated by gstrauss about 1 year 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