Reverted from MapLibre/PMTiles to Leaflet with nginx-proxied OSM raster tiles — the MapLibre approach had unresolvable CSP and theme compat issues. The proxy keeps all browser requests local (no third-party). Also: - Add CPE signal strength and parent AP name to fleet summary SQL and map popup cards (e.g. "Signal: -62 dBm to ap-shady-north") - Add .dockerignore to exclude 8GB PMTiles and node_modules from Docker build context (was causing 10+ minute builds) - Configure mailpit SMTP in dev compose Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
150 lines
5.9 KiB
Plaintext
150 lines
5.9 KiB
Plaintext
map $http_upgrade $connection_upgrade {
|
|
default upgrade;
|
|
'' close;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
# Use Docker's embedded DNS resolver so nginx re-resolves upstream hostnames
|
|
# dynamically instead of caching IPs at startup (prevents 502 after container restarts).
|
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Security headers (server-level -- inherited by all locations unless overridden)
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "0" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
|
|
|
|
# CSP for React SPA with Tailwind CSS and Leaflet maps
|
|
# worker-src required for SRP key derivation Web Worker (Safari won't fall back to script-src)
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' ws: wss:; worker-src 'self' blob:; frame-ancestors 'self'; base-uri 'self'; form-action 'self';" always;
|
|
|
|
# Proxy API requests to the backend service
|
|
# The api container is reachable via Docker internal DNS as "api" on port 8000
|
|
location /api/ {
|
|
# Use a variable so nginx applies the resolver on every request.
|
|
# With a variable in proxy_pass, nginx passes the full request URI as-is
|
|
# (no path stripping), so the upstream receives /api/... correctly.
|
|
set $api_upstream api;
|
|
proxy_pass http://$api_upstream:8000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
# Disable buffering for streaming/SSE endpoints
|
|
proxy_buffering off;
|
|
proxy_read_timeout 300s;
|
|
# Hide nginx server-level CSP — backend sets its own CSP on API responses
|
|
proxy_hide_header Content-Security-Policy;
|
|
}
|
|
|
|
# WebSocket proxy for SSH terminal
|
|
location /ws/ssh {
|
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
|
set $poller_upstream http://poller:8080;
|
|
|
|
proxy_pass $poller_upstream;
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_read_timeout 1800s;
|
|
proxy_send_timeout 1800s;
|
|
|
|
proxy_buffering off;
|
|
proxy_request_buffering off;
|
|
proxy_busy_buffers_size 512k;
|
|
proxy_buffers 8 512k;
|
|
}
|
|
|
|
# Proxy Xpra HTML5 client requests to the winbox-worker container
|
|
location ~ ^/xpra/(\d+)/(.*) {
|
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
|
set $xpra_port $1;
|
|
set $xpra_path $2;
|
|
set $worker_upstream winbox-worker;
|
|
|
|
proxy_pass http://$worker_upstream:$xpra_port/$xpra_path$is_args$args;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
proxy_read_timeout 300s;
|
|
proxy_buffering off;
|
|
# Xpra HTML5 client uses inline event handlers and eval — override the
|
|
# strict server-level CSP. Adding any add_header in a location block
|
|
# replaces all inherited server-level add_header directives in nginx.
|
|
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval' ws: wss: data: blob:; frame-ancestors 'self';" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
}
|
|
|
|
# Proxy OSM raster tiles so the browser never contacts third parties directly
|
|
location ~ ^/osm-tiles/(.+)$ {
|
|
resolver 127.0.0.11 8.8.8.8 valid=300s ipv6=off;
|
|
set $osm_tile_path $1;
|
|
proxy_pass https://tile.openstreetmap.org/$osm_tile_path;
|
|
proxy_ssl_server_name on;
|
|
proxy_set_header Host tile.openstreetmap.org;
|
|
proxy_set_header User-Agent "TOD Fleet Manager (tile proxy)";
|
|
proxy_set_header Accept-Encoding "";
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
expires 7d;
|
|
}
|
|
|
|
# Serve PMTiles with byte range support
|
|
location /tiles/ {
|
|
add_header Access-Control-Allow-Origin "*" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
types {
|
|
application/octet-stream pmtiles;
|
|
}
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# Proxy map font glyphs (MapLibre requests many glyph ranges dynamically)
|
|
location ~ ^/map-fonts/(.+)$ {
|
|
resolver 127.0.0.11 8.8.8.8 valid=300s ipv6=off;
|
|
set $font_path $1;
|
|
proxy_pass https://protomaps.github.io/basemaps-assets/fonts/$font_path;
|
|
proxy_ssl_server_name on;
|
|
proxy_set_header Host protomaps.github.io;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
expires 30d;
|
|
}
|
|
|
|
# Serve static assets with long cache headers
|
|
# Note: add_header in a location block clears parent-block headers,
|
|
# so we re-add the essential security header for static assets.
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# SPA routing: all other requests serve index.html
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# Health check endpoint for container probes
|
|
location /nginx-health {
|
|
access_log off;
|
|
return 200 "OK\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
}
|