I have a little awkward setup with a Apache 2 webserver being the gatekeeper and proxying traffic based on the incoming domain:

<VirtualHost *:80>
  ServerName example.org

  RewriteEngine On
  RewriteRule ^/(.*) http://localhost:3000/$1 [P]

Running under localhost:3000 I have a lighttpd running which serves static content and acts as a reverse proxy for two other services, running on port 3001 and 3002. The configuration looks like this:

# lighttpd will also be used to forward requests to node.js
server.modules = (

# This config is meant to work relative to certain directories,
# it is not meant to be used somewhere globally in /etc/
var.projectRoot = var.CWD

# Setting up paths
server.document-root = var.projectRoot + "/client"

# Port to listen on
server.port          = 3000

# We don't want to provide names of individual files
index-file.names = ( "index.html" )

# Serve all API calls to the API server
$HTTP["url"] =~ "^/api/.*$" {
  proxy.server  = ( "" => (
      ( "host" => "", "port" => 3001 )

# Serve all pages that are not known as static or api routes
# to the page instance
$HTTP["url"] !~ "^/(assets|game|ige|api).*$" {
  proxy.server  = ( "" => (
      ( "host" => "", "port" => 3002 )

The whole setup works fine for the following cases:

  • GET /assets/textures/sources.txt serves a static file from the client directory.
  • GET /api/games/byId/123 retrives the correct data from the API server on port 3001
  • GET / retrieves the page from port 3002

However, the request GET /game (where the game folder has a index.html file) does get served, but changes the URL to http://localhost:3000/game. Or to be more precise: It changes to whatever URL I have specified in the Apache2 vhost, If I put example.org:3000 in there, it will attempt to serve example.org:3000/game, Ignoring the [P] proxy directive.

Things only go wrong when lighttpds "rewrites" to deliver folder/index.html files for folder/ requests. Can anybody tell me why?

The behaviour is the same for Chrome and Firefox and I don't get any HTTP redirects.

  • Perhaps you have your reasons, but nginx is commonly used for that purpose - to hide the bulky and vulnerable Apache behind. I know it's kind of not the answer you wanted, but I'm just trying to get you on the right track. – Zdenek Aug 30 '18 at 17:09

It could be some redirect munging by the lighttpd server, since you don't have a ProxyPassReverse directive specified (it works with RewriteRule too). That said, I don't see anything about your configuration that specifically requires mod_rewrite to perform this proxy: it's best practice to avoid using it when there are dedicated directives to do the job.

Would you mind trying this instead?

<Location />
    ProxyPass        http://localhost:3000
    ProxyPassReverse http://localhost:3000
  • Thanks alot, that did the trick. I never got around really "learning" how Apache2 works and just did some copypasta. – Marcus Riemer Jan 14 '13 at 9:50
  • 2
    I'd use ProxyPreserveHost On instead of ProxyPassReverse; ProxyPassReverse only fixes certain response headers, ProxyPreserveHost will fix all urls generated by the backend. Also it allows to you to use more than one vhost on the connection to the backend. I have no idea why this is not the default, because it is the only sane way imho. – Stefan Jan 14 '13 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.