121 lines
4.0 KiB
Plaintext
121 lines
4.0 KiB
Plaintext
|
|
server {
|
|||
|
|
listen 80;
|
|||
|
|
listen 443 ssl;
|
|||
|
|
listen 443 quic;
|
|||
|
|
listen [::]:443 ssl;
|
|||
|
|
listen [::]:443 quic;
|
|||
|
|
http2 on;
|
|||
|
|
listen [::]:80;
|
|||
|
|
server_name px.ddn-ai.cloud;
|
|||
|
|
index index.html index.htm;
|
|||
|
|
root /www/wwwroot/px.ddn-ai.cloud;
|
|||
|
|
|
|||
|
|
# SSL配置
|
|||
|
|
ssl_certificate /www/server/panel/vhost/cert/px.ddn-ai.cloud/fullchain.pem;
|
|||
|
|
ssl_certificate_key /www/server/panel/vhost/cert/px.ddn-ai.cloud/privkey.pem;
|
|||
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|||
|
|
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384;
|
|||
|
|
ssl_prefer_server_ciphers on;
|
|||
|
|
ssl_session_cache shared:SSL:10m;
|
|||
|
|
ssl_session_timeout 10m;
|
|||
|
|
add_header Strict-Transport-Security "max-age=31536000";
|
|||
|
|
error_page 497 https://$host$request_uri;
|
|||
|
|
|
|||
|
|
# 错误页面
|
|||
|
|
error_page 404 /404.html;
|
|||
|
|
error_page 502 /502.html;
|
|||
|
|
|
|||
|
|
# ========== 新增:图片上传访问配置 ==========
|
|||
|
|
# 图片访问路径: https://px.ddn-ai.cloud/uploads/xxx.png
|
|||
|
|
location /uploads/ {
|
|||
|
|
alias /www/wwwroot/px.ddn-ai.cloud/Image/;
|
|||
|
|
expires 30d;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
add_header Access-Control-Allow-Origin *;
|
|||
|
|
|
|||
|
|
# 支持的图片格式
|
|||
|
|
location ~ \.(jpg|jpeg|png|gif|bmp|webp|svg)$ {
|
|||
|
|
expires 30d;
|
|||
|
|
access_log off;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
# ========== 图片配置结束 ==========
|
|||
|
|
|
|||
|
|
# 后端API代理配置
|
|||
|
|
location /api/ {
|
|||
|
|
proxy_pass http://127.0.0.1:8089/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;
|
|||
|
|
|
|||
|
|
# 支持WebSocket(如果需要)
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
proxy_set_header Connection "upgrade";
|
|||
|
|
|
|||
|
|
# CORS配置(重要:微信小程序需要)
|
|||
|
|
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-Expose-Headers 'Content-Length,Content-Range';
|
|||
|
|
|
|||
|
|
# 处理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 /admin/ {
|
|||
|
|
alias /www/wwwroot/px.ddn-ai.cloud/admin/;
|
|||
|
|
try_files $uri $uri/ /admin/index.html;
|
|||
|
|
|
|||
|
|
# 缓存配置
|
|||
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
|||
|
|
expires 1y;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 微信小程序静态资源(如果需要)
|
|||
|
|
location /miniapp/ {
|
|||
|
|
alias /www/wwwroot/px.ddn-ai.cloud/miniapp/;
|
|||
|
|
expires 7d;
|
|||
|
|
add_header Cache-Control "public";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 禁止访问敏感文件
|
|||
|
|
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md) {
|
|||
|
|
return 404;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 静态资源缓存
|
|||
|
|
location ~ \.well-known {
|
|||
|
|
allow all;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
location ~ \.(gif|jpg|jpeg|png|bmp|swf|webp)$ {
|
|||
|
|
expires 30d;
|
|||
|
|
access_log off;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
location ~ \.(js|css|woff|woff2|ttf|eot)$ {
|
|||
|
|
expires 12h;
|
|||
|
|
access_log off;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 日志配置
|
|||
|
|
access_log /www/wwwlogs/px.ddn-ai.cloud.log;
|
|||
|
|
error_log /www/wwwlogs/px.ddn-ai.cloud.error.log;
|
|||
|
|
}
|