生产环境修正
This commit is contained in:
166
nginx-ggl-xi-plus.conf
Normal file
166
nginx-ggl-xi-plus.conf
Normal file
@@ -0,0 +1,166 @@
|
||||
# 梦回高句丽 - ggl.xi.plus 域名配置
|
||||
# 适用于宝塔面板 Nginx 配置
|
||||
|
||||
# HTTP 重定向到 HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
server_name ggl.xi.plus www.ggl.xi.plus;
|
||||
return 301 https://ggl.xi.plus$request_uri;
|
||||
}
|
||||
|
||||
# HTTPS 主配置
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name ggl.xi.plus www.ggl.xi.plus;
|
||||
|
||||
# 网站根目录
|
||||
root /www/wwwroot/ggl/dist;
|
||||
index index.html index.htm;
|
||||
|
||||
# SSL 证书配置 (宝塔面板自动管理)
|
||||
# ssl_certificate /www/server/panel/vhost/cert/ggl.xi.plus/fullchain.pem;
|
||||
# ssl_certificate_key /www/server/panel/vhost/cert/ggl.xi.plus/privkey.pem;
|
||||
|
||||
# SSL 安全配置
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# 安全头配置
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https:; media-src 'self' https:;" always;
|
||||
|
||||
# Gzip 压缩配置
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_comp_level 6;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/json
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/atom+xml
|
||||
image/svg+xml;
|
||||
|
||||
# 静态资源缓存配置
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|webp)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
add_header Vary "Accept-Encoding";
|
||||
access_log off;
|
||||
|
||||
# 跨域配置
|
||||
add_header Access-Control-Allow-Origin "https://ggl.xi.plus";
|
||||
add_header Access-Control-Allow-Methods "GET, OPTIONS";
|
||||
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
|
||||
}
|
||||
|
||||
# API 请求代理到后端 Node.js 服务
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:4003;
|
||||
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_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
|
||||
# 超时配置
|
||||
proxy_connect_timeout 30s;
|
||||
proxy_read_timeout 60s;
|
||||
proxy_send_timeout 30s;
|
||||
|
||||
# WebSocket 支持
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# 缓冲配置
|
||||
proxy_buffering on;
|
||||
proxy_buffer_size 4k;
|
||||
proxy_buffers 8 4k;
|
||||
|
||||
# 错误处理
|
||||
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
|
||||
}
|
||||
|
||||
# uploads 目录代理到后端
|
||||
location /uploads/ {
|
||||
proxy_pass http://127.0.0.1:4003;
|
||||
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 100M;
|
||||
|
||||
# 缓存配置
|
||||
expires 30d;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
# 健康检查端点
|
||||
location /health {
|
||||
proxy_pass http://127.0.0.1:4003/health;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# 前端路由处理 - 所有其他请求返回 index.html (SPA)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# HTML 文件不缓存
|
||||
location ~* \.html$ {
|
||||
expires -1;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
}
|
||||
}
|
||||
|
||||
# 禁止访问敏感文件
|
||||
location ~ ^/(\.|package\.json|package-lock\.json|\.env|\.git|node_modules|api/|database/) {
|
||||
return 404;
|
||||
}
|
||||
|
||||
# robots.txt
|
||||
location = /robots.txt {
|
||||
add_header Content-Type text/plain;
|
||||
return 200 "User-agent: *\nDisallow: /api/\nDisallow: /uploads/\nSitemap: https://ggl.xi.plus/sitemap.xml\n";
|
||||
}
|
||||
|
||||
# SSL 证书验证目录
|
||||
location /.well-known/ {
|
||||
root /www/wwwroot/ggl;
|
||||
allow all;
|
||||
}
|
||||
|
||||
# 错误页面配置
|
||||
error_page 404 /index.html;
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /www/wwwroot/ggl/dist;
|
||||
}
|
||||
|
||||
# 日志配置
|
||||
access_log /www/wwwlogs/ggl.xi.plus.log combined;
|
||||
error_log /www/wwwlogs/ggl.xi.plus.error.log warn;
|
||||
}
|
||||
|
||||
# 限制请求频率 (防止 DDoS)
|
||||
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
|
||||
limit_req_zone $binary_remote_addr zone=static:10m rate=30r/s;
|
||||
|
||||
# 应用限制到相应的 location
|
||||
# 在 location /api/ 中添加: limit_req zone=api burst=20 nodelay;
|
||||
# 在静态资源 location 中添加: limit_req zone=static burst=50 nodelay;
|
||||
Reference in New Issue
Block a user