I have a 3rd-party ui server running in a docker container, exposed on port 8080.
It seems to expect to load resources with an absolute path: http://localhost:8080/index.html
, http://localhost:8080/js/some_jsfiles
etc.
I want to create a reverse proxy to it so it looks like it is coming from a different path:
https://myserver.com/stormui/index.html
, https://myserver.com/stormui/js/...
first I tried
location /stormui/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
#rewrite ^/stormui/(.*) /$1 break;
proxy_pass http://127.0.0.1:8080/;
}
The index.html page loads, but the browser still tries to load the refered content without the additional path, so I get a 404 on all the javascripts etc referenced from index.html.
Then I tried to use referer to do the rewrite location / {
if ($http_referer ~ "^/stormui/.*") {
rewrite ^/(.*) /stormui/$1 break;
}
root /usr/share/nginx/html;
index index.html index.htm;
...
}
That didn't work, either. Is there a way to do this?
Nginx is an open source web server that can also serve as a reverse proxy. Apart from being used to host websites, it's also one of the most widely used reverse proxy and load balancing solutions.
The following steps briefly outlines the process. 1) The client sends an HTTP CONNECT request to the proxy server. 2) The proxy server uses the host and port information in the HTTP CONNECT request to establish a TCP connection with the target server. 3) The proxy server returns an HTTP 200 response to the client.
Passing Headers to Handle Proxied Requests. Apart from proxy_pass, NGINX offers many other directives to handle requests to your server blocks. One of these directives is proxy_set_header, which lets you pass/rewrite headers to handle proxied requests.
Nginx automatically modifies the request headers it receives from the client when it proxies a request: Nginx removes any empty headers. By default, Nginx removes any header containing underscores from the proxy request. Set the underscores_in_headers directive to on to include them in headers.
I'm not sure I fully understand. Does the HTML (e.g. index.html) from the UI server (running on localhost:8080) contain absolute URLs? If so, you have two options:
I can't answer #2 without more details on what is running on the backend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With