2026-09-09 22:05:00 +08:00
|
|
|
|
worker_processes auto;
|
|
|
|
|
|
error_log /var/log/nginx/error.log warn;
|
|
|
|
|
|
pid /var/run/nginx.pid;
|
|
|
|
|
|
|
|
|
|
|
|
events {
|
|
|
|
|
|
worker_connections 1024;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
http {
|
|
|
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
|
|
default_type application/octet-stream;
|
|
|
|
|
|
|
|
|
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
|
|
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
|
|
|
|
'"$http_user_agent" "$http_x_forwarded_for" '
|
|
|
|
|
|
'request_id=$upstream_http_x_request_id';
|
|
|
|
|
|
|
|
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
|
|
|
|
|
|
|
|
sendfile on;
|
|
|
|
|
|
tcp_nopush on;
|
|
|
|
|
|
tcp_nodelay on;
|
|
|
|
|
|
keepalive_timeout 65;
|
|
|
|
|
|
types_hash_max_size 2048;
|
|
|
|
|
|
|
|
|
|
|
|
# Gzip
|
|
|
|
|
|
gzip on;
|
|
|
|
|
|
gzip_vary on;
|
|
|
|
|
|
gzip_min_length 1024;
|
|
|
|
|
|
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
|
|
|
|
|
|
|
|
|
|
|
# Rate limiting zone
|
|
|
|
|
|
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
|
|
|
|
|
|
limit_req_zone $binary_remote_addr zone=auth:10m rate=5r/s;
|
|
|
|
|
|
limit_req_zone $binary_remote_addr zone=upload:10m rate=10r/s;
|
|
|
|
|
|
|
|
|
|
|
|
upstream backend {
|
|
|
|
|
|
server backend:8080;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-14 10:02:34 +08:00
|
|
|
|
upstream admin_web {
|
|
|
|
|
|
server admin-web:80;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-09 22:05:00 +08:00
|
|
|
|
server {
|
|
|
|
|
|
listen 80;
|
|
|
|
|
|
server_name localhost;
|
|
|
|
|
|
|
|
|
|
|
|
# Health check for nginx itself
|
|
|
|
|
|
location /nginx-health {
|
|
|
|
|
|
return 200 'ok';
|
|
|
|
|
|
add_header Content-Type text/plain;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# API proxy
|
|
|
|
|
|
location /api/ {
|
|
|
|
|
|
limit_req zone=api burst=50 nodelay;
|
|
|
|
|
|
proxy_pass http://backend;
|
|
|
|
|
|
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;
|
|
|
|
|
|
proxy_connect_timeout 30s;
|
|
|
|
|
|
proxy_send_timeout 60s;
|
|
|
|
|
|
proxy_read_timeout 60s;
|
2026-09-14 10:02:34 +08:00
|
|
|
|
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
|
|
|
|
|
|
add_header Pragma "no-cache";
|
2026-09-09 22:05:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# WebSocket proxy
|
|
|
|
|
|
location /ws/ {
|
|
|
|
|
|
proxy_pass http://backend;
|
|
|
|
|
|
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_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
proxy_read_timeout 3600s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Auth endpoints - stricter rate limit
|
|
|
|
|
|
location /api/v1/auth/ {
|
|
|
|
|
|
limit_req zone=auth burst=10 nodelay;
|
|
|
|
|
|
proxy_pass http://backend;
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 20:51:12 +08:00
|
|
|
|
# Admin web —— 管理端产物挂在 /admin/ 子路径下(构建 base=/admin/,
|
|
|
|
|
|
# 见 admin-web/vite.config.ts)。与生产 nginx 保持同一形态:**不剥离**前缀地
|
|
|
|
|
|
# 转发给 admin-web 容器,由容器内的 nginx(admin-web/nginx-admin.conf)
|
|
|
|
|
|
# 统一处理 /admin/ 前缀。三处入口(生产 / 本地整套栈 / staging 直连)因此一致。
|
|
|
|
|
|
location = /admin {
|
|
|
|
|
|
return 301 /admin/;
|
|
|
|
|
|
}
|
|
|
|
|
|
location /admin/ {
|
2026-09-14 10:02:34 +08:00
|
|
|
|
proxy_pass http://admin_web;
|
|
|
|
|
|
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;
|
2026-09-09 22:05:00 +08:00
|
|
|
|
}
|
2026-09-18 20:51:12 +08:00
|
|
|
|
|
|
|
|
|
|
# 其余未匹配路径(不含 /admin、/api、/ws)统一跳转到管理端入口。
|
|
|
|
|
|
# 根路径没有内容,显式跳转以避免"打根路径拿到一个空白/错页"的假成功。
|
|
|
|
|
|
location / {
|
|
|
|
|
|
return 301 /admin/;
|
|
|
|
|
|
}
|
2026-09-09 22:05:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|