mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 03:14:09 +00:00
Adapt main fixes to DEV ownership of split MQTT intake, private projections, lean Compose, and on-demand charts. Preserve deployed migration identities and standalone owner sessions.
212 lines
8.1 KiB
Plaintext
212 lines
8.1 KiB
Plaintext
geo $mesh_trusted_edge {
|
|
default 0;
|
|
172.30.0.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=()";
|
|
}
|
|
|
|
# On-demand repeater footprints occupy the calculator for ~30 s each, so the
|
|
# public edge is deliberately tight. Per-repeater requests also coalesce in
|
|
# the calculator itself.
|
|
limit_req_zone $mesh_client_ip zone=rf_node_requests:10m rate=12r/m;
|
|
|
|
map $host $umami_upstream {
|
|
default "";
|
|
app.ukmesh.com http://100.122.83.39:3012;
|
|
}
|
|
|
|
server {
|
|
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 for static assets
|
|
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;
|
|
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
|
|
|
|
# Operator endpoints are never part of the public frontend 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;
|
|
}
|
|
|
|
# WebSocket upgrade — must come before the /api block
|
|
location = /ws {
|
|
set $backend_upstream http://backend:3000;
|
|
proxy_pass $backend_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 3600s;
|
|
}
|
|
location = /ws/ {
|
|
return 308 /ws;
|
|
}
|
|
|
|
# API and health check proxy to backend
|
|
location ~ ^/(api|healthz|readyz)(/|$) {
|
|
set $backend_upstream http://backend:3000;
|
|
proxy_pass $backend_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;
|
|
}
|
|
|
|
# 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;
|
|
}
|
|
|
|
# HopReach output volume. Metadata/progress are atomically replaced and
|
|
# must be revalidated; completed PNGs may be cached briefly and are
|
|
# cache-busted by run/tile progress in the native map.
|
|
location = /rf-coverage/meta.json {
|
|
alias /rf-coverage-data/output/meta.json;
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
}
|
|
location = /rf-coverage/progress.json {
|
|
alias /rf-coverage-data/output/progress.json;
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
}
|
|
location ~ ^/rf-coverage/tiles/(standard|precision)/([0-9]+-[0-9]+\.png)$ {
|
|
alias /rf-coverage-data/output/tiles/$1/$2;
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "public, max-age=30, stale-while-revalidate=300";
|
|
}
|
|
location ~ "^/rf-coverage/tiles/nodes/(n[0-9a-f]{24})/([0-9]+-[0-9]+\.png)$" {
|
|
alias /rf-coverage-data/output/tiles/nodes/$1/$2;
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "public, max-age=30, stale-while-revalidate=300";
|
|
}
|
|
# On-demand single-repeater RF footprint. The calculator queues and
|
|
# deduplicates the job, then publishes it through meta.json; this call
|
|
# only asks for it. Resolved per request so a calculator restart never
|
|
# blocks nginx startup.
|
|
#
|
|
# The key uses a NAMED capture on purpose: $1 is global per request and
|
|
# the client-IP map above overwrites it (its regex runs for limit_req's
|
|
# key on trusted-edge requests), which silently proxied the IP instead
|
|
# of the public key.
|
|
location ~ "^/rf-coverage/nodes/(?<rf_node_key>[0-9a-fA-F]{64})/request$" {
|
|
limit_req zone=rf_node_requests burst=6 nodelay;
|
|
limit_req_status 429;
|
|
set $rf_node_upstream http://hopreach:8082;
|
|
proxy_pass $rf_node_upstream/api/rf/node/$rf_node_key;
|
|
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;
|
|
proxy_connect_timeout 3s;
|
|
proxy_read_timeout 5s;
|
|
add_header Cache-Control "no-store";
|
|
}
|
|
location /rf-coverage/ {
|
|
return 404;
|
|
}
|
|
|
|
# robots.txt — disallow indexing of app domains
|
|
location = /robots.txt {
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# SPA fallback — client-side routes are extensionless. A path that looks
|
|
# like a file (has a suffix) and does not exist is a genuine miss, not the
|
|
# app shell: answering 200 there is a soft-404 that hides real misses from
|
|
# monitoring and tells scanners every probe "succeeded".
|
|
location / {
|
|
try_files $uri $uri/index.html @spa;
|
|
}
|
|
|
|
location @spa {
|
|
if ($uri ~ "\.[A-Za-z0-9]{1,8}$") {
|
|
return 404;
|
|
}
|
|
try_files /index.html =404;
|
|
}
|
|
|
|
# Cache immutable built assets aggressively.
|
|
location /assets/ {
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# MapLibre's worker bundle keeps a stable filename across releases but its
|
|
# contents change with the library version; a year-long immutable cache
|
|
# pairs a new page bundle with an old worker. Always revalidate .mjs.
|
|
location ~* ^/assets/.*\.mjs$ {
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "no-cache, must-revalidate";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# Always revalidate shell + service worker so deploys appear quickly.
|
|
location = /index.html {
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
}
|
|
location = /sw.js {
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
}
|
|
location = /sw-runtime.js {
|
|
include /etc/nginx/snippets/security-headers.conf;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
}
|
|
}
|