0

NGINX reverse proxy to subdomain

Rourke 6 years ago updated by Gta-Cool 6 years ago 1

I'm running NGINX to handle all the subdomains for my server's web applications. But for Ubooquity I run into some problems. The below block of code is what I use for most applications.


server {
    listen      443 ssl;
    server_name ubooquity.domain.com;
    
    # SSL
    include     /config/nginx/ssl.conf;
    
    location / {
        proxy_pass http://ubooquity:2202/;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        # HTTP 1.1 support
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
    
    location /admin {
        proxy_pass http://ubooquity:2203/admin/;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        # HTTP 1.1 support
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
    
    location /admin-res {
        proxy_pass http://ubooquity:2203/admin-res/;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        # HTTP 1.1 support
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}
server {
 listen 80;
 server_name ubooquity.domain.com;
 return 301 https://$host$request_uri;
}

To make this run I had to empty the reverse proxy prefix setting. I'm using docker containers for everything. ubooquity.domain.com works great. However ubooquity.domain.com/admin doesn't. It does load the login screen, but without the styling. I noticed it's trying to load the CSS from ubooquity.domain.com/admin-res/admin.css so that's why I added the /admin-res block. This still doesn't work.


I really want to run this through a subdomain. Does anyone have experience with this? How can I fix this?

Hi, you weren't far from the solution, there is also a third route /admin-api.