作者:じ☆ve不哭
发布时间:2023-10-27T15:07:56
在项目中使用SSE向前台推送数据,发现本地没问题,但是服务器连接SSE接口出现超时不能请求问题。排查后发现是Nginx的问题。
# 反向代理配置
server {
listen 80;
server_name xx.xx.xx.xx;
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 REMOTE-HOST $remote_addr;
proxy_set_header HTTP_AUTHORIZATION $http_authorization;
# SSE 连接时的超时时间
proxy_read_timeout 1800s;
# 取消缓冲
proxy_buffering off;
# 关闭代理缓存
proxy_cache off;
# 禁用分块传输编码
#chunked_transfer_encoding off
location ^~ /api/ {
proxy_pass http://localhost:82/;
}
location ^~ /dev/file/download/ {
proxy_pass http://localhost:82;
}
location / {
root /home/xxxxx/xxxx-admin-web;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
cd /usr/local/nginx
# 验证nginx.conf配置是否正确
./sbin/nginx -t
# 重启nginx
./sbin/nginx -s reload