2

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.

1

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.

1
  • sounds very encouraging ;-) I can't 'teach' the backend unless i have lots of time to spend rewriting 3rd party UI interfaces. I guess the port forwarding idea is probably easier after all – MrE Sep 3 '15 at 5:25
0

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

server {
    listen       8000 ssl;
    server_name  sub-domain.domain.com:8000;
    #auth stuff
    location / {
        proxy_pass                  http://my-service-monitor1;
    }
}

server {
    listen       8001 ssl;
    server_name  sub-domain.domain.com:8001;
    #auth stuff
    location / {
        proxy_pass                  http://my-service-monitor2;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.