NGINX reverse proxy for Synology DiskStation

Well, I’ve been tinkering with NGINX for a while at home, up till now I had a somewhat working reverse proxy setup (to access my stuff, when I’m not at home or away).

What didn’t work so far was the DSM web interface. Basically, because the interface is using absolute paths in some CSS/JS includes, which fuck up the whole interface.

After some googling and looking through the NGINX documentation I thought “Why don’t I create a vHost for each application that is being served by the reverse proxy?”.

And after looking further into the documentation, out came this simple reverse proxy statement:

And as you can see, it works:

Synology DSM via NGINX
Synology DSM via NGINX

9 thoughts to “NGINX reverse proxy for Synology DiskStation”

  1. Hi,
    Thanks for your post.

    I’m having troubles to configure mine. Could you please describe why you are using the auth_basic and auth_basic_user_file statement ?

    And finaly, is your nginx reverse proxy sitting on the DiskStation ? (Mine is on a dedicated machine)

    1. Hey misterneno,

      I’m using auth_basic and auth_basic_user_file since the reverse proxy is available from the Internet. Even if the DiskStation has it’s own password database, I wanted an additional level.

      The NGINX is running on a dedicated machine (same as yours then).

  2. Hey,

    Thanks for the tip, I found your webpage looking for how to install nginx on synology, do you have a nice tutorial for that?

    Once installed, I will definitely try your trick! Can’t wait!

    /glattering

    1. Hey glattering,

      as I stated above, the NGINX reverse proxy is running on another system. But it should be as simple as replacing the proxy-pass/proxy-redirect ips with 127.0.0.1.

  3. Hello again,

    It’s been a while…
    I heard I can use nginx on my router.
    I have an ASUS RTN16 running Tomato.
    DO you know where I could find information on how to install nginx on Tomato?
    I have been searching without success.
    I also heard some version of tomato include already nginx but I couldn’t find how to find out if my version of tomato has it or not.
    Any help is welcome 🙂

  4. Glattering, I have a ASUS RTN16 too. Instead of Tomato, I am using TomatoRAF (a version that is still being updated) You can find it here:
    http://victek.is-a-geek.com/

    In that version, under webserver you have the option to turn nginx on or off and to save custom configuration. Up until recently I was using that nginx as a reverse proxy.

  5. Hi,

    I have NGINX running on a raspberrypi and I also want to access my DSM via a reverse proxy. Unfortunately I don’t have the option to use subdomains. I can only use paths. I managed to get it working, at least partially. I can log in and do some of the things, but I cannot e.g. open the FileManager because of some script error. I suppose it’s still a miss configuration of my reverse proxy. Maybe someone has an idea. In order to have a workaround for the absolute paths I used a rewrite in the root location with a condition.

    server {
    client_max_body_size 2m;
    listen 443 ssl spdy;
    server_name http://www.myServer.net myServer.net;

    access_log /var/log/nginx/myServer_access.log;
    error_log /var/log/nginx/myServer_error.log;

    # certificate locations
    ssl_certificate /etc/nginx/ssl/myServer.crt;
    ssl_certificate_key /etc/nginx/ssl/myServer.key;

    location / {
    if ($http_referer ~ /nas/) {
    rewrite ^(.*) /nas/$1 permanent;
    }

    return 404;

    }

    location /nas/ {
    auth_basic “Restricted”;
    auth_basic_user_file /etc/nginx/.htpasswd;
    rewrite /nas/(.*) /$1 break;
    proxy_pass http://nas_upstream;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host ‘ip.ofmy.ds’;
    proxy_redirect http://ip.ofmy.ds/ /nas/;
    sub_filter ‘”/’ ‘”/nas/’;
    sub_filter_once off;
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.

This site uses Akismet to reduce spam. Learn how your comment data is processed.