98 lines
3.2 KiB
Plaintext
98 lines
3.2 KiB
Plaintext
server {
|
||
listen 80;
|
||
server_name cp.mzh.one;
|
||
|
||
# Let's Encrypt 验证路径(如需证书续期)
|
||
location /.well-known/acme-challenge/ {
|
||
root /opt/mottery/frontend/dist;
|
||
}
|
||
|
||
# 其它HTTP请求重定向到HTTPS
|
||
location / {
|
||
return 301 https://$host$request_uri;
|
||
}
|
||
}
|
||
|
||
server {
|
||
listen 443 ssl;
|
||
server_name cp.mzh.one;
|
||
|
||
# SSL证书配置(你自己处理路径)
|
||
ssl_certificate /ssl/cp.mzh.one/cp.mzh.one.pem;
|
||
ssl_certificate_key /ssl/cp.mzh.one/cp.mzh.one.key;
|
||
|
||
# 前端静态资源 - 修复路径
|
||
location / {
|
||
root /opt/mottery/frontend/dist;
|
||
index index.html;
|
||
try_files $uri $uri/ /index.html last;
|
||
|
||
# 添加调试信息
|
||
add_header X-Debug-Path $document_root$uri always;
|
||
}
|
||
|
||
# 静态资源缓存 - 确保assets路径正确
|
||
location /assets/ {
|
||
root /opt/mottery/frontend/dist;
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
add_header X-Debug-Path $document_root$uri always;
|
||
}
|
||
|
||
# 其他静态资源
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
||
root /opt/mottery/frontend/dist;
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
add_header X-Debug-Path $document_root$uri always;
|
||
}
|
||
|
||
# 后端API代理 - 修复路径转发
|
||
location /api/ {
|
||
# 使用Docker默认网桥的网关地址,并正确转发路径
|
||
proxy_pass http://172.17.0.1:8000/api/;
|
||
|
||
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 30s;
|
||
proxy_read_timeout 30s;
|
||
|
||
# 解决跨域问题
|
||
add_header Access-Control-Allow-Origin *;
|
||
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
|
||
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization";
|
||
|
||
# 处理OPTIONS请求
|
||
if ($request_method = 'OPTIONS') {
|
||
add_header Access-Control-Allow-Origin *;
|
||
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
|
||
add_header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization";
|
||
add_header Access-Control-Max-Age 1728000;
|
||
add_header Content-Type 'text/plain; charset=utf-8';
|
||
add_header Content-Length 0;
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# 健康检查端点
|
||
location /health {
|
||
proxy_pass http://172.17.0.1:8000/health;
|
||
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;
|
||
}
|
||
|
||
# 错误页面
|
||
error_page 500 502 503 504 /50x.html;
|
||
location = /50x.html {
|
||
root /usr/share/nginx/html;
|
||
}
|
||
|
||
client_max_body_size 50M;
|
||
} |