1. 问题现象
通过域名访问 https://api-uat.sfxs.com/sse/subscribe?token=Bearer%20eyJUxMiJ9.eyJhY2NvdW50IjoiYWRtaWZ0NvZGUiOiIwMDEiLCJyb2xidXNlcm5hbWUiOiLotoXnuqfnrqHnkIblkZgifQ.tlz9N61Y4
一直无法正常连接
2. 问题解决
nginx.conf进行配置
server {location /sse {# 确保使用正确的协议版本proxy_http_version 1.1;# 启用长连接proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";# 传递主机头信息proxy_set_header Host $host;# 避免缓存proxy_cache_bypass $http_upgrade;# 连接到后端服务proxy_pass http://api-uat.sfxs.com/sse;# 调整超时时间以适应长连接proxy_read_timeout 3600s;proxy_send_timeout 3600s;# 关闭缓冲proxy_buffering off;}# CORS 配置(如果需要)add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';....}
}
再次访问显示如图, 但是页面还是无法访问, 是因为我们在后端已经设置过CORS 配置,取消即可