Project

General

Profile

Rewrite paths when using reverse proxy

Added by b99andla 4 months ago

I am pretty new to lighttpd and am using it to reverse proxy a local running crun process under a local ip: 10.200.1.2. I have gotten the proxy working, so it proxies the call correctly from localhost/customer into my 10.200.1.2 process on port 80. But now (in my view), I need to also fix all paths that are returned (they are returned in html as /static/js/main.js but should be returned as /customer/static/js/main.js, how can I do this?

My config:

$HTTP["url"] =~ "^/customer" {
        proxy.server  =  ( "" => ( "" => ("host" => "10.200.1.2", "port" => 80 )))
        proxy.header = (
                "map-urlpath" => (
                        "/customer" => "/" 
                ),
        ),
}


Replies (1)

RE: Rewrite paths when using reverse proxy - Added by gstrauss 4 months ago

I need to also fix all paths that are returned (they are returned in html as /static/js/main.js but should be returned as /customer/static/js/main.js, how can I do this?

lighttpd does not rewrite the contents of the response body. You need to find a solution to do that yourself. One of the easiest solutions to avoid needing to rewrite the contents of the response body is to use paths relative to the customer root rather than paths rooted at '/'.

    (1-1/1)