server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # auth_request subrequest inherits this: must fit large AI/OCR image bodies client_max_body_size 60m; # ---- license gate (server-side enforcement via auth_request) ---- location = /_license { internal; proxy_pass http://it-tools-relay:8091/check; proxy_set_header X-Machine-Id $http_x_machine_id; proxy_set_header X-Tool $http_x_tool; proxy_connect_timeout 5s; proxy_read_timeout 10s; } # admin console SPA route (exact match beats the /admin/ API prefix below, # otherwise nginx 301s /admin -> /admin/ and the API proxy swallows the UI) location = /admin { try_files $uri /index.html; } # admin console API (relay does its own Bearer auth; must beat SPA fallback) location /admin/ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://it-tools-relay:8091; proxy_connect_timeout 5s; proxy_read_timeout 30s; } # MCP endpoint (JSON-RPC streamable HTTP + result file download). # Relay does its own Bearer-token auth here — no auth_request subrequest. # Boundary regex: must NOT swallow the /mcp-connect SPA page (prefix /mcp would). location ~ ^/mcp(/|$) { client_max_body_size 60m; 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_pass http://it-tools-relay:8091; proxy_connect_timeout 5s; proxy_read_timeout 600s; proxy_send_timeout 600s; } # license relay (card activation etc; auth gate itself must stay open) location /relay/ { client_max_body_size 2g; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://it-tools-relay:8091/; proxy_connect_timeout 5s; proxy_read_timeout 600s; proxy_send_timeout 600s; } # AI retouch (iopaint container on host) - protected location /api/v1/ { auth_request /_license; client_max_body_size 60m; proxy_pass http://host.docker.internal:8060/api/v1/; proxy_connect_timeout 10s; proxy_read_timeout 300s; } # OCR service (rapidocr container on host) - protected location = /api/ocr { auth_request /_license; client_max_body_size 30m; proxy_pass http://host.docker.internal:5000/ocr; proxy_connect_timeout 10s; proxy_read_timeout 120s; } # Google translate via relay container (host proxy required in CN) - protected location = /api/translate { auth_request /_license; proxy_pass http://it-tools-relay:8091/translate; proxy_connect_timeout 10s; proxy_read_timeout 30s; } # MyMemory fallback translation - protected location = /api/translate-mm { auth_request /_license; proxy_pass https://api.mymemory.translated.net/get; proxy_ssl_server_name on; proxy_set_header Host api.mymemory.translated.net; proxy_connect_timeout 10s; proxy_read_timeout 30s; } # ---- SPA shell & service worker: MUST revalidate every load ---- # Without this header browsers heuristically cache index.html/sw.js and the # PWA keeps serving a stale precache after deploys (2026-10-30: users were # stuck on an old my-ip page that leaked the server egress IP). location = /index.html { add_header Cache-Control "no-cache, must-revalidate"; try_files $uri =404; } location = /sw.js { add_header Cache-Control "no-cache, must-revalidate"; add_header Service-Worker-Allowed "/"; try_files $uri =404; } location = /manifest.webmanifest { add_header Cache-Control "no-cache, must-revalidate"; try_files $uri =404; } # hashed build assets are content-addressed: cache forever location /assets/ { add_header Cache-Control "public, max-age=31536000, immutable"; try_files $uri =404; } location / { add_header Cache-Control "no-cache, must-revalidate"; try_files $uri $uri/ /index.html; } }