# nas.example.com -> https://192.0.2.18:5001 (example written by jt-waf-mgr; check it, save it as
# /etc/nginx/sites-available/nas.example.com.conf, link it into sites-enabled, then nginx -t and reload).
# ModSecurity: switch it on for this site on the jt-waf-mgr sites page afterwards (an approved change).
# Synology DSM: add this proxy under DSM Control Panel > Security > Trusted proxies, or DSM's
# auto block sees every client as the proxy.
map $http_upgrade $nas_connection_upgrade {
default upgrade;
'' close;
}
# Synology Photos for iOS sends "multipart/form-data; charset=utf-8; boundary=...". ModSecurity accepts
# only one ";" before the boundary and would not inspect such a body at all (from outside the
# protection set refuses it). Exactly this shape goes, with the Content-Type in standard form, to the
# loopback server at the end, which inspects it in full like any other request.
map $content_type $nas_mp_ct {
"~*^multipart/form-data;[ \t]*charset=[A-Za-z0-9_-]{1,20};[ \t]*(boundary=[A-Za-z0-9'()+_,./:=?-]{1,70})$" "multipart/form-data; $1";
default "";
}
# only the names served on port 5001 get a TLS handshake: a scan of the address, or a guessed
# name, is refused (keep one such block per port; leave it out if the port has one already)
server {
listen 5001 ssl default_server;
listen [::]:5001 ssl default_server;
ssl_reject_handshake on;
}
server {
listen 5001 ssl;
listen [::]:5001 ssl;
http2 on;
server_name nas.example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
server_tokens off;
# the local network only (delete these lines to publish the site)
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 127.0.0.0/8;
allow ::1;
deny all;
add_header Strict-Transport-Security "max-age=15768000" always;
client_max_body_size 1g;
error_page 419 = @nas_mp_fix; # see the map $nas_mp_ct above
if ($nas_mp_ct) { return 419; }
location @nas_mp_fix {
modsecurity off; # inspected by the loopback server below
proxy_pass http://127.0.0.1:15001;
proxy_set_header Host $host:$server_port;
proxy_set_header Content-Type $nas_mp_ct;
proxy_set_header X-Jt-Client $remote_addr; # the only source address the loopback server trusts
proxy_set_header X-Forwarded-For "";
proxy_set_header X-Real-IP "";
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
location / {
proxy_pass https://192.0.2.18:5001;
proxy_http_version 1.1;
proxy_ssl_verify off; # a private back end with its own certificate
proxy_ssl_server_name on;
# the port browsers use: if a port forward or a stream in front changes it, write that port here
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr; # replaced, never appended (a client cannot forge it)
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $nas_connection_upgrade;
proxy_request_buffering off;
proxy_buffering off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
access_log /var/log/nginx/nas.example.com.access.log;
error_log /var/log/nginx/nas.example.com.error.log;
}
# loopback only: the Synology Photos iOS uploads from the server above, inspected by ModSecurity
# (no allow/deny: after real_ip the address is the client's; listening on 127.0.0.1 is the limit)
server {
listen 127.0.0.1:15001;
server_name nas.example.com;
modsecurity on;
set_real_ip_from 127.0.0.1;
real_ip_header X-Jt-Client;
client_max_body_size 1g;
server_tokens off;
location / {
proxy_pass https://192.0.2.18:5001;
proxy_ssl_verify off;
proxy_ssl_server_name on;
proxy_set_header Host $host:5001;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
access_log off; # logged by the public server
error_log /var/log/nginx/nas.example.com.error.log;
}
sudo ln -s /etc/nginx/sites-available/nas.example.com.conf /etc/nginx/sites-enabled/nas.example.com.conf
sudo nginx -t && sudo systemctl reload nginx
# qnap.example.com -> https://192.0.2.19:443 (example written by jt-waf-mgr; check it, save it as
# /etc/nginx/sites-available/qnap.example.com.conf, link it into sites-enabled, then nginx -t and reload).
# ModSecurity: switch it on for this site on the jt-waf-mgr sites page afterwards (an approved change).
# QNAP QTS: the web interface and the apps (Qfile, QuMagie, Qsync) use this one port. QTS blocks the
# address it sees after failed logins (Network Access Protection): behind a proxy check what your QTS
# version does with X-Forwarded-For, or one person's wrong password can lock everyone out.
map $http_upgrade $qnap_connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name qnap.example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
server_tokens off;
# the local network only (delete these lines to publish the site)
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 127.0.0.0/8;
allow ::1;
deny all;
add_header Strict-Transport-Security "max-age=15768000" always;
client_max_body_size 1g;
location / {
proxy_pass https://192.0.2.19:443;
proxy_http_version 1.1;
proxy_ssl_verify off; # a private back end with its own certificate
proxy_ssl_server_name on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr; # replaced, never appended (a client cannot forge it)
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $qnap_connection_upgrade;
proxy_request_buffering off;
proxy_buffering off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
access_log /var/log/nginx/qnap.example.com.access.log;
error_log /var/log/nginx/qnap.example.com.error.log;
}
server {
listen 80;
listen [::]:80;
server_name qnap.example.com;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 127.0.0.0/8;
allow ::1;
deny all;
return 301 https://$host$request_uri;
}
sudo ln -s /etc/nginx/sites-available/qnap.example.com.conf /etc/nginx/sites-enabled/qnap.example.com.conf
sudo nginx -t && sudo systemctl reload nginx
# app.example.com -> http://192.0.2.20:8080 (example written by jt-waf-mgr; check it, save it as
# /etc/nginx/sites-available/app.example.com.conf, link it into sites-enabled, then nginx -t and reload).
# ModSecurity: switch it on for this site on the jt-waf-mgr sites page afterwards (an approved change).
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name app.example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
server_tokens off;
# the local network only (delete these lines to publish the site)
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 127.0.0.0/8;
allow ::1;
deny all;
add_header Strict-Transport-Security "max-age=15768000" always;
client_max_body_size 10m;
location / {
proxy_pass http://192.0.2.20:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr; # replaced, never appended (a client cannot forge it)
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 120s;
}
access_log /var/log/nginx/app.example.com.access.log;
error_log /var/log/nginx/app.example.com.error.log;
}
server {
listen 80;
listen [::]:80;
server_name app.example.com;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 127.0.0.0/8;
allow ::1;
deny all;
return 301 https://$host$request_uri;
}
sudo ln -s /etc/nginx/sites-available/app.example.com.conf /etc/nginx/sites-enabled/app.example.com.conf
sudo nginx -t && sudo systemctl reload nginx
# chat.example.com -> http://192.0.2.21:3000 (example written by jt-waf-mgr; check it, save it as
# /etc/nginx/sites-available/chat.example.com.conf, link it into sites-enabled, then nginx -t and reload).
# ModSecurity: switch it on for this site on the jt-waf-mgr sites page afterwards (an approved change).
map $http_upgrade $chat_connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name chat.example.com;
ssl_certificate /etc/ssl/example/fullchain.pem;
ssl_certificate_key /etc/ssl/example/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
server_tokens off;
# the local network only (delete these lines to publish the site)
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 127.0.0.0/8;
allow ::1;
deny all;
add_header Strict-Transport-Security "max-age=15768000" always;
client_max_body_size 10m;
location / {
proxy_pass http://192.0.2.21:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr; # replaced, never appended (a client cannot forge it)
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $chat_connection_upgrade;
proxy_read_timeout 120s;
}
access_log /var/log/nginx/chat.example.com.access.log;
error_log /var/log/nginx/chat.example.com.error.log;
}
server {
listen 80;
listen [::]:80;
server_name chat.example.com;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow 127.0.0.0/8;
allow ::1;
deny all;
return 301 https://$host$request_uri;
}
sudo ln -s /etc/nginx/sites-available/chat.example.com.conf /etc/nginx/sites-enabled/chat.example.com.conf
sudo nginx -t && sudo systemctl reload nginx