Files
ukmesh/nginx.website.conf

117 lines
3.9 KiB
Plaintext

geo $mesh_trusted_edge {
default 0;
172.30.0.20 1;
172.30.0.21 1;
172.18.30.20 1;
172.18.30.21 1;
}
map "$mesh_trusted_edge:$http_cf_connecting_ip" $mesh_client_ip {
default $remote_addr;
~^1:([0-9A-Fa-f:.]+)$ $1;
}
map $uri $mesh_permissions_policy {
default "geolocation=(), camera=(), microphone=()";
~^/(feed|repeater)?/?$ "geolocation=(self), camera=(), microphone=()";
}
server {
# 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;
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;
}
# 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.
location / {
include /etc/nginx/snippets/security-headers.conf;
add_header Cache-Control "no-cache, no-store, must-revalidate";
try_files $uri $uri/index.html /index.html;
}
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";
}
}