0

I'm running a Synology NAS with DSM 5.x. I finally have a working nginx reverse proxy from another server with the below configuration.

What I don't want is all the locations, if possible. The DSM web interface uses each of the below url fragments as part of it's interface. There's no URL base, and no option to add one.

My question is-- is it possible in nginx with proxy_pass or proxy_redirect or rewrite (or something else) to not have to list all the separate locations individually? (I've tried dozens of combinations of these for several days, and was never able to get anything except the below to work.)

nginx.conf

http {
    upstream dsm {
        server 1.1.1.1:5000;
    }
    server {
        location /dsm/ {
            include proxy_headers;
            proxy_pass http://dsm/;
        }
        location /scripts/ {
            include proxy_headers;
            proxy_pass http://dsm;
        }
        location /synoSDSjslib/ {
            include proxy_headers;
            proxy_pass http://dsm;
        }
        location /webapi/ {
            include proxy_headers;
            proxy_pass http://dsm;
        }
        location /webdefault/ {
            include proxy_headers;
            proxy_pass http://dsm;
        }
        location /webfm/ {
            include proxy_headers;
            proxy_pass http://dsm;
        }
        location /webman/ {
            include proxy_headers;
            proxy_pass http://dsm;
        }
    }
}

proxy_headers

proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;

Edit: Let me clarify-- I did leave out a few details. I would like a single address & port with multiple base url's that can reach multiple DSM's without base url's like /scripts & /webapi from clashing/colliding/colluding. I know that multiple addresses & ports are possible. What I'm looking for, if it's possible, is a way to ssh into the server serving nginx with a -L local forward, forwarding a single port, so that I can reach multiple DSM's with one single ssh forwarded port. The solution I have now does work, but only for one DSM. If I add a 2nd, they collide.

1 Answer 1

0

The location blocks have nothing similar, so combining them with a regex is a bit time consuming and complicated.

Instead, we can just route all the requests to the DSM.

There are three methods to have multiple DSM servers without clashing.

Method #1: Virtual Hosts

You will need to configure your DNS to point your chosen virtual host at the NGINX server.

http {
    #DSM 1 Standard DSM setup
    upstream dsm1 {
        server 1.1.1.1:5000;
    }
    #DSM 2 - DSM has different Port, same IP Address
    upstream dsm2 {
        server 1.1.1.1:6000;
    }
    #DSM 3 - DSM has different IP Address
    upstream dsm3 {
        server 2.1.1.1:5000;
    }
    #DSM 1 Standard DSM setup
    server {
        listen       80;
        server_name dsm1.mydomain.com;
        location / {
            include proxy_headers;
            proxy_pass http://dsm1/;
    }
    #DSM 2 - DSM has different Port, same IP Address
    server {
        listen       80;
        server_name dsm2.mydomain.com;
        location / {
            include proxy_headers;
            proxy_pass http://dsm2/;
    }
    #DSM 3 - DSM has different IP Address
    server {
        listen       80;
        server_name dsm3.mydomain.com;
        location / {
            include proxy_headers;
            proxy_pass http://dsm3/;
    }

Method #2, Different NGINX ports

Each server can be accessed on it's own port on the NGINX server

http {
    #DSM 1 Standard DSM setup
    upstream dsm1 {
        server 1.1.1.1:5000;
    }
    #DSM 2 - DSM has different Port, same IP Address
    upstream dsm2 {
        server 1.1.1.1:6000;
    }
    #DSM 3 - DSM has different IP Address
    upstream dsm3 {
        server 2.1.1.1:5000;
    }
    #DSM 1 Standard DSM setup
    server {
        listen       80;
        location / {
            include proxy_headers;
            proxy_pass http://dsm1/;
    }
    #DSM 2 This DSM server is available on another port (8081). Access using http://nginx_ip:8081
    server {
        listen       81;
        location / {
            include proxy_headers;
            proxy_pass http://dsm1/;
    }
}

Method #3: Rewrites

Each server can be accessed via a sub-url on the NGINX server. May not work depending on the DSM webpage configuration, and whether or not it has relative instead of absolute URLs.

http {
    #DSM 1
    upstream dsm1 {
      server 1.1.1.1:5000
    }
    #DSM 2
    upstream dsm2 {
      server: 1.1.1.2:5000
    }
    server {
      listen 80;
      location /dsm1/(?<dsmurl>.*) {
        include proxy_headers;
        proxy_pass http://dsm1/$dsmurl
      }
      location /dsm2/(?<dsmurl>.*) {
        include proxy_headers;
        proxy_pass http://dsm2/$dsmurl
      }
     }
}
3
  • I have other servers on different ports and locations. I'm trying to isolate/consolidate this one server/port/location so that all the /scripts etc. don't clash.
    – snapshoe
    Commented Oct 16, 2015 at 23:41
  • Answer updated to reflect additional requirements. Commented Oct 17, 2015 at 0:11
  • So, my only options are 1/2) different addresses/ports, or 3) urls that don't work. That was the point of the question-- DSM's web interface isn't designed with a single url base. I'm trying to figure out if rewrites or redirects or something is possible to consolidate everything into one single sub/base url. I got option 2) working before, and 1) is just a variation on 2). So, it sounds like what I want is not possible. I do have it working-- it just looks ugly and can't handle 2+ DSM's on a single address & port.
    – snapshoe
    Commented Oct 17, 2015 at 1:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .