4

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


}
1
  • please specify your version of lighttpd Apr 23, 2018 at 11:52

1 Answer 1

3
+50

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

2
  • 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., somehost.com/xxx/file should be obtained from somehost.com:8080/file. Make sense? Apr 23, 2018 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. Apr 23, 2018 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .