Host a Website on Synology NAS with Custom nginx and Let's Encrypt

By Eddie Power Oct 20, 2026 in Sysadmin 8 min read
nginx Synology NAS Let's Encrypt HTTPS Web Station

I host a handful of my own sites, including this blog, on a Synology NAS at home. Web Station and the built-in reverse proxy cover most needs, but sooner or later you want something the GUI can't do: a bare-domain redirect, a custom header, a special location block, or a site that only exists to serve one file. That's when you reach for your own nginx config.

This guide shows the way I do it on DSM 7: a small config file of my own in nginx's include folder, using a Let's Encrypt certificate that DSM manages and renews. It also covers the gotchas that have bitten me, including the 502 errors you can get after a Web Station restart.

If all you need is HTTPS in front of an app, start with my Synology reverse proxy with Let's Encrypt guide instead. It's GUI-only and the safer option. This guide is for when you've outgrown it.

Prerequisites

  • A Synology NAS on DSM 7 (I'm on 7.4) with Web Station installed.
  • SSH enabled (Control Panel > Terminal & SNMP) and an admin account. My Synology SSH hardening guide covers doing that safely with keys.
  • A domain with a DNS A record pointing at your public IP, here called example.com.
  • Router port forwards for TCP 80 and 443 to the NAS. Port 80 matters even if you only want HTTPS: Synology's own help says port 80 must be open for Let's Encrypt domain validation and renewal.
  • Comfort with a terminal. You'll be editing files as root, and a typo can take down every site on the NAS until you fix it.

A fair warning: Synology doesn't officially document hand-written nginx files. Everything here is reversible, but keep a copy of your config in your home folder and re-check it after DSM updates.

How nginx is wired on DSM 7

DSM generates its main config at /etc/nginx/nginx.conf. Don't edit that file, because DSM rewrites it. Instead, look at what it includes:

grep -n "include conf.d" /etc/nginx/nginx.conf

You'll see lines such as include conf.d/http.*.conf; inside the http block. On DSM 7, /etc/nginx/conf.d is a symlink to /usr/local/etc/nginx/conf.d. So any file you create there named http.something.conf is loaded as part of the http block, which means you can put complete server { } blocks in it.

List the folder and you'll see plenty of other files:

ls -la /usr/local/etc/nginx/conf.d/

Most are symlinks with long random IDs that Web Station and DSM packages create and manage. Leave them alone. Your own file should be a normal file with a clear name, such as http.mysite.conf.

Step 1: Get a Let's Encrypt certificate in DSM

Let DSM handle issuing and renewing the certificate. It does this well.

  1. Go to Control Panel > Security > Certificate and click Add.
  2. Choose Add a new certificate, then Get a certificate from Let's Encrypt.
  3. Enter your domain (example.com), your email address, and any extra names such as www.example.com under Subject Alternative Name.
  4. Click Done and wait for validation.

Synology's certificate help page explains the options, and notes that DSM renews Let's Encrypt certificates automatically before they expire, as long as port 80 is reachable.

Step 2: Find the certificate files

DSM keeps each certificate in its own folder with a random ID under /usr/syno/etc/certificate/_archive/. That folder is root-only, so this loop prints the names and expiry date for each one:

sudo sh -c 'for d in /usr/syno/etc/certificate/_archive/*/; do
  [ -f "$d/cert.pem" ] || continue
  echo "== $d"
  openssl x509 -in "$d/cert.pem" -noout -enddate
  openssl x509 -in "$d/cert.pem" -noout -text | grep -A1 "Subject Alternative Name" | tail -1
done'

Find the folder whose names match your domain. Inside it you'll find fullchain.pem (your certificate plus the chain) and privkey.pem. In the examples below I'll call that folder <CERT_ID>. Never post the contents of privkey.pem anywhere, and don't copy it into your web root.

Step 3: Write your server blocks

Create the file:

sudo vi /usr/local/etc/nginx/conf.d/http.mysite.conf

Here's a complete example. It redirects HTTP to HTTPS but keeps the Let's Encrypt validation path working on port 80, then serves a static site over HTTPS:

# HTTP: keep ACME validation working, send everything else to HTTPS
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    location ^~ /.well-known/acme-challenge/ {
        root /var/lib/letsencrypt;
        default_type text/plain;
    }
    location / {
        return 301 https://example.com$request_uri;
    }
}

# HTTPS
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com www.example.com;

    ssl_certificate     /usr/syno/etc/certificate/_archive/<CERT_ID>/fullchain.pem;
    ssl_certificate_key /usr/syno/etc/certificate/_archive/<CERT_ID>/privkey.pem;

    root /volume1/web/mysite;
    index index.html;

    add_header X-Content-Type-Options nosniff always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location / {
        try_files $uri $uri/ =404;
    }
    # Never serve hidden files such as .git or .env
    location ~ /\. {
        deny all;
    }
}

A few notes:

  • The /var/lib/letsencrypt path is where DSM's own default server looks for challenge files. Confirm it on your NAS with grep -n -A2 "acme-challenge" /etc/nginx/nginx.conf and use whatever path it shows.
  • Don't add default_server to your listen lines. DSM already owns the default server on 80 and 443.
  • To proxy to an app (a container on port 8080, say) instead of serving files, replace the location / block with proxy_pass http://127.0.0.1:8080; plus the usual proxy_set_header Host $host; and proxy_set_header X-Forwarded-Proto $scheme; lines.
  • Make sure the web server can read your files. On DSM, content under /volume1/web is normally readable by the http group.

The nginx docs on configuring HTTPS servers explain each directive if you want to go further.

Step 4: Test, then reload

Always test before you reload. If the config is invalid, nginx refuses to load it, and on a NAS that can mean every site and the DSM web interface go down together.

sudo nginx -t

You want to see syntax is ok and test is successful. Then reload without dropping connections:

sudo nginx -s reload

The -t and -s switches are documented on the nginx command-line page. sudo systemctl reload nginx also works on DSM 7.

Step 5: Check it from the outside

From another machine (or your phone on mobile data), check the redirect and the certificate:

curl -sI http://example.com/ | head -3
curl -sI https://example.com/ | head -3
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -enddate

The first should show a 301 pointing at https://, the second a 200, and the third your domain with an expiry date in the future. To test from the NAS itself before DNS has updated, use curl --resolve example.com:443:127.0.0.1 -skI https://example.com/.

The Apache port 915 gotcha

If any of your Web Station sites use Apache HTTP Server 2.4 as their back-end, nginx doesn't serve them directly. It proxies them to Apache listening locally. On my NAS that's 127.0.0.1:915, which you can confirm with:

grep -rho "proxy_pass http://127.0.0.1:[0-9]*" /usr/local/etc/nginx/conf.d-available/ | sort | uniq -c

The gotcha: after a Web Station restart, a package update or a DSM update, nginx can come back up while Apache is still down. Your nginx-only sites (including the custom ones from this guide) work fine, while the Apache-backed ones return 502 Bad Gateway. It looks like you broke something with your new config, when really Apache is down. Check it like this:

sudo netstat -tlnp | grep ':915'
curl -sI http://127.0.0.1:915/ | head -1
sudo systemctl status pkg-apache24

If nothing is listening on 915, restart Apache from Package Center > Apache HTTP Server 2.4 > Stop/Run, or:

sudo systemctl restart pkg-apache24

Your port number may differ, so trust what the grep shows over my 915.

Troubleshooting

  • nginx -t fails with "conflicting server name ... ignored". That's a warning, not an error, but it means another server block (often a Web Station portal or a reverse proxy rule) already claims that hostname. Remove the duplicate, or only one of them will ever answer.
  • cannot load certificate. The path or <CERT_ID> is wrong, or you pointed at cert.pem instead of fullchain.pem. Re-run the loop from Step 2.
  • Browser says the certificate is for a different name. Your request is reaching a different server block, usually DSM's default. Check that server_name matches exactly, and that you're testing the right hostname.
  • Let's Encrypt renewal fails. Port 80 isn't reaching the NAS, or your port 80 block redirects the challenge path somewhere it can't be served. Keep the acme-challenge location as shown.
  • 403 Forbidden. File permissions. The http user can't read your web folder.
  • Your config vanished after an update. Restore it from your home folder copy, run nginx -t, and reload. This is why you keep a copy.
  • After a certificate renewal the old expiry still shows. nginx reads certificates when it loads. Check the date with the openssl s_client command above after the first renewal. If it's stale, run sudo nginx -s reload. A weekly DSM Task Scheduler job running nginx -t && nginx -s reload as root is a cheap safety net.

Wrapping up

The pattern is simple once you've seen it: let DSM own the certificate, keep your config in your own clearly named http.*.conf file, and never reload without nginx -t. It's how I run redirects and one-off hosts here without fighting Web Station. Just keep that backup copy handy, and re-check things after every DSM update.

Share this article

E
Eddie Power admin

Eddie Power is a full-stack web developer based in Frankston, Victoria, with more than a decade of experience building websites, Laravel and PHP applications and iOS apps. He uses Linux, Windows and macOS every day, self-hosts this blog on a Synology NAS and writes practical guides for all three.

Comments (0)

No comments yet. Be the first to leave one!

Leave a Comment

Comments are moderated and will appear after approval.