2013450
2013450

Reputation: 71

lighttpd configuration to proxy/rewrite from one domain to another

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:

Is it possible?

Upvotes: 7

Views: 8338

Answers (2)

gstrauss
gstrauss

Reputation: 2404

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

Upvotes: 0

AizeLauna
AizeLauna

Reputation: 343

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" ),
  )
}

Upvotes: 5

Related Questions