120 lines
3.6 KiB
Plaintext
120 lines
3.6 KiB
Plaintext
# shanxia2.0 一体化门户 - Nginx 配置
|
||
# 部署路径:/etc/nginx/conf.d/shanxia2.0.conf
|
||
# 访问地址:http://121.43.228.102:9911
|
||
|
||
server {
|
||
listen 9911;
|
||
server_name 121.43.228.102;
|
||
|
||
root /iflytek/shanxia2.0/web/dist;
|
||
index index.html index.htm;
|
||
|
||
client_max_body_size 50M;
|
||
|
||
# access_log /iflytek/soft/nginx/nginx120/logs/shanxia2.0-access.log main;
|
||
# error_log /iflytek/soft/nginx/nginx120/logs/shanxia2.0-error.log warn;
|
||
|
||
gzip on;
|
||
gzip_vary on;
|
||
gzip_min_length 1024;
|
||
gzip_comp_level 6;
|
||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml application/json application/x-font-ttf font/opentype image/svg+xml;
|
||
|
||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||
add_header X-Content-Type-Options "nosniff" always;
|
||
add_header X-XSS-Protection "1; mode=block" always;
|
||
|
||
# API 代理(shanxia2.0 使用 /api 前缀,对应 FastAPI 9111)
|
||
location ^~ /api/ {
|
||
proxy_pass http://127.0.0.1:9111;
|
||
|
||
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-Port $server_port;
|
||
|
||
proxy_set_header Authorization $http_authorization;
|
||
proxy_pass_header Authorization;
|
||
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 60s;
|
||
proxy_read_timeout 60s;
|
||
|
||
add_header Access-Control-Allow-Origin * always;
|
||
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS, PATCH' always;
|
||
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||
|
||
if ($request_method = 'OPTIONS') {
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# 后端 health(可选,便于 nginx 层探测)
|
||
location = /health {
|
||
proxy_pass http://127.0.0.1:9111/health;
|
||
proxy_set_header Host $host;
|
||
access_log off;
|
||
}
|
||
|
||
# 小程序静态资源公网目录(源文件:/iflytek/shanxia2.0/app/assets)
|
||
# 访问:http://121.43.228.102:9911/shanxia-static/images/logo.svg
|
||
location ^~ /shanxia-static/ {
|
||
alias /iflytek/shanxia2.0/app/assets/;
|
||
autoindex off;
|
||
expires 30d;
|
||
add_header Cache-Control "public, max-age=2592000";
|
||
add_header Access-Control-Allow-Origin * always;
|
||
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
||
|
||
if ($request_method = 'OPTIONS') {
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
location = /shanxia-static/health {
|
||
access_log off;
|
||
default_type text/plain;
|
||
return 200 "shanxia miniprogram static ok\n";
|
||
}
|
||
|
||
# 静态资源长缓存
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2|ttf|eot)$ {
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
try_files $uri =404;
|
||
add_header Access-Control-Allow-Origin *;
|
||
}
|
||
|
||
# index.html 不缓存
|
||
location = /index.html {
|
||
expires -1;
|
||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
||
}
|
||
|
||
# Vue Hash 路由 SPA
|
||
location / {
|
||
try_files $uri $uri/ /index.html;
|
||
}
|
||
|
||
location /health-web {
|
||
access_log off;
|
||
return 200 "shanxia2.0 web healthy\n";
|
||
add_header Content-Type text/plain;
|
||
}
|
||
|
||
location ~ /\. {
|
||
deny all;
|
||
access_log off;
|
||
log_not_found off;
|
||
}
|
||
|
||
error_page 404 /index.html;
|
||
error_page 500 502 503 504 /50x.html;
|
||
|
||
location = /50x.html {
|
||
root /iflytek/soft/nginx/nginx120/html;
|
||
internal;
|
||
}
|
||
}
|