lighttpd configuration to proxy/rewrite from one domain to another
Asked Answered
S

2

7

i need to setup proxy/rewrite on lighttpd!

i have server1, which serves via http 2 different web app paths:

* http://server1/path1
* http://server1/path2

also, i have lighttpd server in front of server1

i want to setup rewriting and/or proxing on lighttpd, so that each of the 2 paths would be served as root path on different domains:

* requests to http://server2.com/* are proxied/rewrited to http://server1/path1/*
* requests to http://server3.com/* are proxied/rewrited to http://server1/path2/*

important:

  • server2.com and server3.com can access server1 only via http
  • redirects are not the option, users of server2.com & server3.com shouldn't not know that the actual web apps are served from different paths of server1.

Is it possible?

Sock answered 26/1, 2013 at 11:38 Comment(1)
Unfortunately, your question isn't about programming or programming tools, so we can't help you here. However, our friends over at Server Fault probably can - be sure to search before asking and read their FAQ for help on constructing a good question.Assertive
T
5

Your need is known by lighttpd developers from several years.

It is answered by a workaround or new feature depending on the version.

Lighttpd 1.4

A workaround is explained in the bugtracker : bug #164

$HTTP["url"] =~ "(^/path1/)" {   
  proxy.server  = ( "" => ("" => ( "host" => "127.0.0.1", "port" => 81 ))) 
}

$SERVER["socket"] == ":81" {   
  url.rewrite-once = ( "^/path1/(.*)$" => "/$1" )   
  proxy.server  = ( "" => ( "" => ( "host" => "server2.com", "port" => 80 ))) 
}

Lighttpd 1.5

They added this feature with this command (official documentation) :

proxy-core.rewrite-request : rewrite request headers or request uri.

$HTTP["url"] =~ "^/path1" {
  proxy-co...

  proxy-core.rewrite-request = (
    "_uri" => ( "^/path1/?(.*)" => "/$1" ),
    "Host" => ( ".*" => "server2.com" ),
  )
}
Tetramethyldiarsine answered 19/10, 2013 at 13:39 Comment(2)
FWIW, it seems that the 1.5 version has been abandoned before reaching the first release. I guess this means we're stuck with the workaround.Fermi
For v1.4, the solution doesn't work. It redirects but doesn't change the pathOvertask
S
0

Update: lighttpd 1.4.46 (released in 2017) introduced proxy.header which can perform limited URL-prefix rewriting. More info at lighttpd mod_proxy

Spenserian answered 24/6, 2022 at 22:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.