Files
ukmesh/nginx.website.conf

157 lines
5.7 KiB
Plaintext

geo $mesh_trusted_edge {
default 0;
172.30.0.20 1;
}
map "$mesh_trusted_edge:$http_cf_connecting_ip" $mesh_client_ip {
default $remote_addr;
~^1:([0-9A-Fa-f:.]+)$ $1;
}
map $host $umami_upstream {
default "";
~^(www\.)?ukmesh\.com$ http://100.122.83.39:3012;
}
server {
# SPA navigation shares a document policy with the repeater and feed pages.
set $mesh_permissions_policy "geolocation=(self), camera=(), microphone=()";
# The remotely managed development-tunnel route still targets port 80.
# Keep the hardened internal port for Compose health checks and Anubis.
listen 80;
listen 8080;
root /usr/share/nginx/html;
index index.html;
resolver 127.0.0.11 valid=10s ipv6=off;
# The production tracker uses two same-origin paths. Keep credentials
# and the referring URL out of the analytics upstream.
location ~ ^/_stats/(?<umami_path>script[.]js|api/send)$ {
if ($umami_upstream = "") { return 404; }
proxy_pass $umami_upstream/$umami_path$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $mesh_client_ip;
proxy_set_header X-Forwarded-For $mesh_client_ip;
proxy_set_header Cookie "";
proxy_set_header Authorization "";
proxy_set_header Referer "";
proxy_hide_header Set-Cookie;
}
include /etc/nginx/snippets/security-headers.conf;
# Gzip compression — critical for large API responses (coverage ~26 MB → ~2-3 MB)
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
gzip_min_length 256;
# Operator endpoints are never part of the public website origin.
location ~ ^/(local-api|backend|ml-path-learner|operations|observer-registrations|metrics)(/|$) {
return 404;
}
# Software probes for executable web files get an honest 404. There is no
# PHP/ASP/JSP/CGI runtime anywhere in this stack and the served root is a
# static build, so a 200 on these paths is always a lie. The SPA fallback
# used to answer every one of them with the app shell and 200, which reads
# as a hit to commodity scanners and keeps them coming back.
location ~* \.(?:php[0-9]?|phtml|phar|asp|aspx|jsp|jspx|cgi|pl|py|sh|env|ini)(?:/|$) {
return 404;
}
# WordPress path probes (directory sweeps, xmlrpc) get the same honest 404:
# there is no WordPress here, and these are the only extensionless paths a
# scanner hits that this SPA can never own as a client-side route.
location ~* ^/(?:wp-(?:admin|content|includes|login|json|xmlrpc)|xmlrpc\.php)(?:/|$) {
return 404;
}
# Proxy API calls through to the app service so live stats work
location /api/ {
set $backend_api_upstream http://backend:3000;
proxy_pass $backend_api_upstream;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $mesh_client_ip;
proxy_set_header X-Forwarded-For $mesh_client_ip;
}
location = /readyz {
set $backend_ready_upstream http://backend:3000;
proxy_pass $backend_ready_upstream;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $mesh_client_ip;
proxy_set_header X-Forwarded-For $mesh_client_ip;
}
# One canonical WebSocket contract. Both identity headers are overwritten
# from the trusted edge mapping; caller forwarding chains are never passed.
location = /ws {
set $backend_ws_upstream http://backend:3000;
proxy_pass $backend_ws_upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $mesh_client_ip;
proxy_set_header X-Forwarded-For $mesh_client_ip;
proxy_read_timeout 86400;
}
location = /ws/ {
return 308 /ws;
}
# Static SEO files — serve directly, not via SPA fallback
location = /robots.txt {
try_files $uri =404;
}
location = /sitemap.xml {
include /etc/nginx/snippets/security-headers.conf;
add_header Content-Type application/xml;
try_files $uri =404;
}
# OS Terrain 50 terrain tiles (terrarium-encoded PNG)
location /terrain-tiles/ {
alias /terrain-tiles/;
include /etc/nginx/snippets/security-headers.conf;
add_header Access-Control-Allow-Origin *;
add_header Cache-Control "public, max-age=604800, immutable";
try_files $uri =404;
}
# Prefer the prerendered route shell (for example /topology/index.html)
# without redirecting the public URL to this container's internal port.
# Client-side routes are extensionless: a path that looks like a file and
# does not exist is a real 404, not the app shell. Serving the shell with
# 200 (a soft-404) hid real misses from monitoring and told scanners every
# probe "succeeded".
location / {
include /etc/nginx/snippets/security-headers.conf;
add_header Cache-Control "no-cache, no-store, must-revalidate";
try_files $uri $uri/index.html @spa;
}
location @spa {
if ($uri ~ "\.[A-Za-z0-9]{1,8}$") {
return 404;
}
try_files /index.html =404;
}
location /assets/ {
include /etc/nginx/snippets/security-headers.conf;
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
location = /index.html {
include /etc/nginx/snippets/security-headers.conf;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
}