Proxy URL to different port via Lighttpd

I cannot seem to proxy a URL to another port on same hostname. I have user interface (Angular 5) running on somehost:8080 and the rest of the web application on somehost.com (port 80). I'd like to proxy http://somehost.com/xxx to http://somehost.com:8080. Not sure if my configuration is correct or in the right place.

$HTTP["host"] =~ "somehost\.com$" {

        $HTTP["url"] =~ "(^/xxx/)" {
          proxy.server  = ( "" => ("" => ( "host" => "somehost.com", "port" => 8080 )))
        }

        url.rewrite-if-not-file = (
                "^/(.*)" => "/index.php/$1",
        )


}

Solution 1:

From your question it looks like you want to serve http://somehost.com/xxx/file from http://somehost.com:8080/file. In that case your config is wrong, because it is trying to serve http://somehost.com:8080/xxx/file instead. You need to add a url.rewrite-once:

  url.rewrite-once = ( "^/xxx/(.*)$" => "/$1" )
  proxy.server  = ( "" => ( # proxy all file extensions / prefixes
    "" => # optional label to identify requests in logs
      ( "host" => "somehost",
        "port" => 8080
      )
    )
  )

Depending on your version of lighttpd, you might or might not be able to call url.rewrite-once from within a $HTTP["url"] match.

Also make sure that you have loaded the mod_proxy and mod_rewrite modules with:

server.modules += ( "mod_proxy" )
server.modules += ("mod_rewrite")

More info on proxy.server: https://redmine.lighttpd.net/projects/1/wiki/Docs_ModProxy More info on url.rewrite-once: https://redmine.lighttpd.net/projects/1/wiki/docs_modrewrite#urlrewrite-repeat