我有一个痛苦的问题。我使用Flask-SocketIO将后台进程的某些状态更新到网页上。 对于我的例子,我的应用程序被放入机器A,IP 170.8.8.8监控端口5000,我把nginx放在机器B中,IP 170.8.8.9也监控端口5000.所以我想访问B中的IP:5000跳转到IP:5000 in A.以下是我在机器B中的nginx配置:
upstream cuitccol.com{ #the name of server cluster
server 170.8.8.8:5000 max_fails=5 fail_timeout=50s; #for the first web server
}
server {
listen 5000;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://cuitccol.com;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
如果我直接访问A中的IP,我浏览器的网页可以不断更新后台进程的状态。但如果我访问放置nginx的B,网页就无法不断更新状态,我必须刷新网页才能获得下一个状态。我浏览器的控制台有一个错误如下:
WebSocket connection to 'ws://170.8.8.9:5000/socket.io/?EIO=3&transport=websocket&sid=4a2ec29f7f834a0bb289b21f03c3e47c' failed: Error during WebSocket handshake: Unexpected response code: 200
我不知道哪里出了问题。 nginx或flask-socketio。你能提一些建议吗? 非常感谢〜
答案 0 :(得分:0)
将您的配置更改为
location / {
proxy_pass http://cuitccol.com;
proxy_http_version 1.1;
}
location /socket.io {
proxy_pass http://cuitccol.com/socket.io;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
看看它是否有帮助。升级头应该用于Socket,而不是用于其他端点