Let's say I have several web UI sites used to monitor backend services.
I would like to make them accessible from the web (secured by Auth) but ideally bundled under one sub-domain, and accessible through various URLs like:
https://monitor.mydomain.com/my-service-monitor/
Using nginx, if i use a rewrite rule like
server {
listen 443 ssl;
server_name monitor.mydomain.com;
# auth stuff here...
location /my-service-monitor/ {
rewrite ^/my-service-monitor(/.*)$ $1 break;
proxy_pass http://my-service-monitor;
}
}
what happens is that the redirect works, but because all the static content refers to the root URL, it doesn't show as expected (because the back end site is outputting HTML looking at the root / url, not the relative URL monitor.mydomain.com/my-service-monitor/...
How can I fix this problem, or is there an easier solution to this? (I could use multiple subdomains, but that's too much outside exposure IMO)
I was thinking of redirecting (with a return 301 ...) to the sub-domain root URL but on a different port, and then add a server bloc listening on that port proxying to the server, but I feel like that's going to be trouble with auth.
Any insight would be appreciated.
You need to teach your backend application to generate correct URLs for the page. There are people who are, apparently, writing custom lua code to modify the returned HTML from within nginx, but honestly I'd recommend avoiding that because it is insane.
I ended up assigning each site a different port, on the same sub-domain
the catch is that the server block should include the port in the server_name. At first I only had the listen value list the port but it would not work with multiple sites on the same server_name, so one needs