Ben Zittlau
Ben Zittlau

Reputation: 2485

Proxying a sub folder using Lighttpd mod_proxy

I'm having problems getting mod_proxy to properly forward traffic to a different webserver running on the same machine for a predefined subfolder. Ideally domain.com/docs should forward to 127.0.0.1:3000 and all other traffic should stay on domain.com. The rewrite rules here are for a wordpress install that runs on domain.com:

$HTTP["host"] =~ "(^|\.)domain\.com" {
 $HTTP["url"] =~ "^/docs" {
  proxy.server  = ( "" => (( "host" => "127.0.0.1", "port" => 3000 )))
 } 
 $HTTP["url"] !~ "^/docs/(.*)" {
  url.rewrite = (
   "^/(.*)\.(.+)$" => "$0",
   "^/wp/(.*)$" => "$0",
   "^/(.+)/?$" => "/index.php/$1"
  )
  server.document-root = "/mnt/webroot/html"
 }
}

I've been beating my head against this for a while now, so any suggestions are welcome.

Upvotes: 4

Views: 1991

Answers (1)

Ben Zittlau
Ben Zittlau

Reputation: 2485

I eventually figured out the issue that was causing this to not work like I expected.

The way lighttpd's rewrite mod works it evaluates all the url.rewrite commands before it evaluates it's $HTTP["url"] conditionals, which means that any url.rewrite commands placed within an $HTTP["url"] conditional will have no effect.

I wasn't able to find a good solution to the implementation I was looking for with this limitation, and instead ended up pushing some of the rewriting downstream to the other server (node in this case) that I was proxying the traffic to.

This is loosely referred to in lighttpd's ModRewrite docs with this line:

NOTE: url rewriting does not work within a $HTTP["url"] conditional.

Upvotes: 2

Related Questions