2026-01-19 11:03:08 +00:00
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name localhost;
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
index index.html;
|
|
|
|
|
|
|
|
|
|
# Gzip Compression
|
|
|
|
|
gzip on;
|
|
|
|
|
gzip_vary on;
|
|
|
|
|
gzip_min_length 10240;
|
|
|
|
|
gzip_proxied expired no-cache no-store private auth;
|
|
|
|
|
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
|
|
|
|
|
gzip_disable "MSIE [1-6]\.";
|
|
|
|
|
|
|
|
|
|
# 增加上传文件大小限制
|
2026-01-30 00:52:50 +00:00
|
|
|
client_max_body_size 500M;
|
2026-01-19 11:03:08 +00:00
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 后端API代理
|
|
|
|
|
location /api/ {
|
|
|
|
|
proxy_pass http://backend: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;
|
|
|
|
|
|
|
|
|
|
# 增加API超时时间
|
|
|
|
|
proxy_read_timeout 300s;
|
|
|
|
|
proxy_send_timeout 300s;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 07:43:08 +00:00
|
|
|
location = /docs {
|
|
|
|
|
proxy_pass http://backend:8000/docs;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location = /redoc {
|
|
|
|
|
proxy_pass http://backend:8000/redoc;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location = /openapi.json {
|
|
|
|
|
proxy_pass http://backend:8000/openapi.json;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location = /docs/oauth2-redirect {
|
|
|
|
|
proxy_pass http://backend:8000/docs/oauth2-redirect;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 12:10:39 +00:00
|
|
|
# 上传文件代理 (使用 ^~ 提高优先级,避免被静态文件正则匹配拦截)
|
|
|
|
|
location ^~ /uploads/ {
|
2026-01-19 11:03:08 +00:00
|
|
|
proxy_pass http://backend: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;
|
|
|
|
|
|
|
|
|
|
# 静态资源缓存配置
|
|
|
|
|
expires 30d;
|
|
|
|
|
add_header Cache-Control "public, no-transform";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Cache static assets
|
|
|
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
|
|
|
|
expires 30d;
|
|
|
|
|
add_header Cache-Control "public, no-transform";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_page 500 502 503 504 /50x.html;
|
|
|
|
|
location = /50x.html {
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
}
|
2026-03-27 07:43:08 +00:00
|
|
|
}
|