- location = /index.html、/sw.js、/manifest.webmanifest 加 no-cache,must-revalidate(PWA 预缓存不再赖旧版 my-ip 等页面) - /assets/ 内容哈希资源 immutable 长缓存 - location / 兜底 no-cache;已部署验证线上响应头;CHANGELOG 补条
96 lines
3.1 KiB
Nginx Configuration File
96 lines
3.1 KiB
Nginx Configuration File
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;
|
|
}
|
|
|
|
# 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;
|
|
}
|
|
}
|