Files
PaperPhone/client/nginx.conf
2026-03-28 22:41:12 +08:00

79 lines
3.4 KiB
Nginx Configuration File

# ─────────────────────────────────────────────────────────────────
# Nginx config for PaperPhone — serves PWA + reverse-proxy to API
#
# This file is an envsubst template. At container start the
# Dockerfile CMD substitutes ${SERVER_URL} and writes the final
# config to /etc/nginx/conf.d/paperphone.conf.
#
# Docker Compose: SERVER_URL = http://server:3000
# Zeabur: SERVER_URL = ${ZEABUR_WEB_URL} (e.g. http://10.43.x.x:3000)
# ─────────────────────────────────────────────────────────────────
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# ── Compression ──────────────────────────────────────────────
gzip on;
gzip_types text/plain text/css application/javascript application/json application/wasm;
gzip_min_length 1024;
gzip_vary on;
# ── Security headers ─────────────────────────────────────────
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "no-referrer" always;
# ── Static asset caching ─────────────────────────────────────
location ~* \.(css|js|wasm|png|jpg|webp|ico|svg|woff2?)$ {
expires 7d;
add_header Cache-Control "public, max-age=604800, immutable";
}
# Service worker — always revalidate so updates propagate
location = /sw.js {
add_header Cache-Control "no-cache, no-store, must-revalidate";
expires 0;
}
# ── WebSocket — proxy to backend ─────────────────────────────
location /ws {
proxy_pass ${SERVER_URL};
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 $remote_addr;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
# ── REST API — proxy to backend ──────────────────────────────
location /api/ {
proxy_pass ${SERVER_URL};
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;
client_max_body_size 51m;
# Long-poll & upload timeout
proxy_read_timeout 120s;
proxy_send_timeout 120s;
}
# ── Health check (forwarded to backend) ──────────────────────
location /health {
proxy_pass ${SERVER_URL};
}
# ── SPA fallback ─────────────────────────────────────────────
location / {
try_files $uri $uri/ /index.html;
}
}