99 lines
2.7 KiB
Plaintext
99 lines
2.7 KiB
Plaintext
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# 日志配置
|
|
access_log /var/log/nginx/dianshang_access.log;
|
|
error_log /var/log/nginx/dianshang_error.log;
|
|
|
|
# 客户端上传文件大小限制
|
|
client_max_body_size 10M;
|
|
|
|
# API 接口代理
|
|
location /api/ {
|
|
proxy_pass http://server:8080;
|
|
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 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# 缓冲设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
}
|
|
|
|
# 健康检查
|
|
location /health {
|
|
proxy_pass http://server:8080;
|
|
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 /static/ {
|
|
alias /var/www/static/;
|
|
expires 30d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# 上传文件服务
|
|
location /uploads/ {
|
|
alias /var/www/uploads/;
|
|
expires 7d;
|
|
add_header Cache-Control "public";
|
|
}
|
|
|
|
# 默认页面
|
|
location / {
|
|
return 200 '{"message": "Dianshang API Server is running"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
|
|
# 错误页面
|
|
error_page 404 /404.html;
|
|
error_page 500 502 503 504 /50x.html;
|
|
|
|
location = /50x.html {
|
|
return 500 '{"error": "Internal Server Error"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
|
|
location = /404.html {
|
|
return 404 '{"error": "Not Found"}';
|
|
add_header Content-Type application/json;
|
|
}
|
|
}
|
|
|
|
# HTTPS 配置(可选)
|
|
# server {
|
|
# listen 443 ssl http2;
|
|
# server_name your-domain.com;
|
|
#
|
|
# ssl_certificate /etc/nginx/ssl/cert.pem;
|
|
# ssl_certificate_key /etc/nginx/ssl/key.pem;
|
|
# ssl_session_timeout 1d;
|
|
# ssl_session_cache shared:SSL:50m;
|
|
# ssl_session_tickets off;
|
|
#
|
|
# ssl_protocols TLSv1.2 TLSv1.3;
|
|
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
|
|
# ssl_prefer_server_ciphers off;
|
|
#
|
|
# add_header Strict-Transport-Security "max-age=63072000" always;
|
|
#
|
|
# location / {
|
|
# proxy_pass http://server:8080;
|
|
# 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;
|
|
# }
|
|
# } |