222 lines
7.4 KiB
Plaintext
222 lines
7.4 KiB
Plaintext
server {
|
||
listen 80;
|
||
server_name hzdyjsweb.camasort.com;
|
||
|
||
# 网站根目录
|
||
root /root/hzdyjsweb9091/dist;
|
||
index index.html index.htm;
|
||
|
||
# 访问日志和错误日志
|
||
access_log /var/log/nginx/hzdyjsweb.camasort.com.access.log;
|
||
error_log /var/log/nginx/hzdyjsweb.camasort.com.error.log;
|
||
|
||
# 客户端最大上传文件大小
|
||
client_max_body_size 50M;
|
||
|
||
# Vue Router History模式支持 - 所有路由都指向index.html
|
||
location / {
|
||
try_files $uri $uri/ /index.html;
|
||
|
||
# 添加安全头
|
||
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;
|
||
}
|
||
|
||
# 静态资源缓存配置
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
add_header Vary "Accept-Encoding";
|
||
|
||
# 如果文件不存在,返回404而不是跳转到index.html
|
||
try_files $uri =404;
|
||
}
|
||
|
||
# HTML文件缓存配置
|
||
location ~* \.(html|htm)$ {
|
||
expires 0;
|
||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||
add_header Pragma "no-cache";
|
||
}
|
||
|
||
# SSE专用代理配置(重要:必须放在其他API配置之前)
|
||
location ^~ /prod-api/resource/sse {
|
||
proxy_pass http://47.121.125.41:8080/resource/sse;
|
||
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;
|
||
|
||
# SSE特殊配置
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Connection "";
|
||
proxy_buffering off;
|
||
proxy_cache off;
|
||
|
||
# SSE需要更长的超时时间
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 86400s; # 24小时
|
||
proxy_read_timeout 86400s; # 24小时
|
||
|
||
# SSE响应头设置
|
||
proxy_set_header Accept "text/event-stream";
|
||
proxy_set_header Cache-Control "no-cache";
|
||
proxy_set_header Connection "keep-alive";
|
||
|
||
# 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,clientid';
|
||
add_header Access-Control-Allow-Credentials true;
|
||
|
||
if ($request_method = 'OPTIONS') {
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# SSE关闭接口专用配置
|
||
location ^~ /prod-api/resource/sse/close {
|
||
proxy_pass http://47.121.125.41:8080/resource/sse/close;
|
||
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;
|
||
|
||
# 普通API配置(不需要SSE特殊配置)
|
||
proxy_connect_timeout 30s;
|
||
proxy_send_timeout 30s;
|
||
proxy_read_timeout 30s;
|
||
|
||
# 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,clientid';
|
||
add_header Access-Control-Allow-Credentials true;
|
||
|
||
if ($request_method = 'OPTIONS') {
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# Warm-Flow工作流UI代理配置(重要:必须放在Vue路由配置之前)
|
||
location ^~ /prod-api/warm-flow-ui/ {
|
||
proxy_pass http://47.121.125.41:8080/warm-flow-ui/;
|
||
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;
|
||
|
||
# 支持WebSocket和SSE
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection "upgrade";
|
||
proxy_buffering off;
|
||
proxy_cache off;
|
||
|
||
# 超时设置
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 60s;
|
||
proxy_read_timeout 86400s;
|
||
|
||
# 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,clientid';
|
||
|
||
if ($request_method = 'OPTIONS') {
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# API代理配置(使用^~确保优先级,避免被Vue路由配置干扰)
|
||
location ^~ /prod-api/ {
|
||
proxy_pass http://47.121.125.41: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;
|
||
|
||
# 支持WebSocket和SSE
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection "upgrade";
|
||
proxy_buffering off;
|
||
proxy_cache off;
|
||
|
||
# 超时设置
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 60s;
|
||
proxy_read_timeout 86400s;
|
||
|
||
# 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,clientid';
|
||
|
||
if ($request_method = 'OPTIONS') {
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# 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 ~ /\. {
|
||
deny all;
|
||
access_log off;
|
||
log_not_found off;
|
||
}
|
||
|
||
# 禁止访问备份文件
|
||
location ~ ~$ {
|
||
deny all;
|
||
access_log off;
|
||
log_not_found off;
|
||
}
|
||
}
|
||
|
||
# HTTPS配置(可选,推荐生产环境使用)
|
||
# server {
|
||
# listen 443 ssl http2;
|
||
# server_name hzdyjsweb.camasort.com;
|
||
#
|
||
# # SSL证书配置
|
||
# ssl_certificate /path/to/your/certificate.crt;
|
||
# ssl_certificate_key /path/to/your/private.key;
|
||
#
|
||
# # SSL配置
|
||
# 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 off;
|
||
# ssl_session_cache shared:SSL:10m;
|
||
# ssl_session_timeout 10m;
|
||
#
|
||
# # 其他配置与HTTP相同
|
||
# root /root/hzdyjsweb9091/dist;
|
||
# index index.html index.htm;
|
||
#
|
||
# # ... 复制上面的location配置 ...
|
||
# }
|
||
#
|
||
# # HTTP重定向到HTTPS(如果启用HTTPS)
|
||
# server {
|
||
# listen 80;
|
||
# server_name hzdyjsweb.camasort.com;
|
||
# return 301 https://$server_name$request_uri;
|
||
# } |