54 lines
1.5 KiB
Nginx Configuration File
54 lines
1.5 KiB
Nginx Configuration File
|
|
# hxops_nginx.conf
|
|
# 放置于 /etc/nginx/conf.d/hxops.conf
|
|
|
|
server {
|
|
listen 80;
|
|
server_name 192.168.100.230; # 或域名
|
|
|
|
# 1. 前端静态资源 (动静分离)
|
|
location / {
|
|
root /opt/hxops/frontend/dist;
|
|
index index.html;
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
# 静态资源缓存策略
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 30d;
|
|
add_header Cache-Control "public, no-transform";
|
|
}
|
|
}
|
|
|
|
# 2. 后端 API 反向代理
|
|
location /api/ {
|
|
# 转发到 Gunicorn (Gevent)
|
|
proxy_pass http://127.0.0.1:5000;
|
|
|
|
# 关键配置:关闭缓冲以支持 SSE 流式输出
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
|
|
# 传递客户端真实 IP
|
|
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_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
|
|
# 超时设置 (应对长对话)
|
|
proxy_read_timeout 300s;
|
|
proxy_connect_timeout 75s;
|
|
}
|
|
|
|
# 开启 Gzip 压缩
|
|
gzip on;
|
|
gzip_min_length 1k;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
|
|
gzip_vary on;
|
|
gzip_disable "MSIE [1-6]\.";
|
|
}
|