3

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


}
Michael Niño
  • 91
  • 1
  • 6

1 Answers1

3

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

Luca Gibelli
  • 2,611
  • 1
  • 21
  • 29
  • My Angular 5 development server is running on port 8080. I want to serve all URLs located on port somehost.com:8080 from somehost.com/xxx. E.g., http://somehost.com/xxx/file should be obtained from http://somehost.com:8080/file. Make sense? – Michael Niño Apr 23 '18 at 17:53
  • Yes, I understood your original question correctly then. You need to rewrite urls as per my answer. Your current config only maps somehost.com:80 to somehost:8080 without removing xxx/ from the url. – Luca Gibelli Apr 23 '18 at 19:45