【发布时间】:2018-04-18 19:12:02
【问题描述】:
我正在尝试使用前端的 socket.io 和后端的 Flask-Socketio 建立 websocket 连接。但是,前端给了我错误
WebSocket connection to 'ws://myserver.com/socket.io/?EIO=3&transport=websocket&sid=0514a0aa99f346e7ad717770f9911c89' failed: WebSocket is closed before the connection is established.
我感觉这是由于我的 uwsgi 或 nginx 配置造成的。
这是我正在使用的 uwsgi 配置:
[uwsgi]
base = /var/www/webapp
file = %(base)/run.py
callable = app
pythonpath = %(base)
socket = /tmp/uwsgi.sock
chmod-socket = 666
http-websockets = true
gevent = 1000
processes = 1
threads = 2
enable-threads = true
single-interpreter = true
master = true
chdir = /var/www/webapp
fs-reload = %(base)/app/
touch-reload = %(base)/run.py
py-autoreload = 1
harakiri = 3600
这里是 nginx 配置的相关部分:
location /socket.io/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
使用有问题吗
socket = /tmp/uwsgi.sock
来自带有
的 uwsgi 配置uwsgi_pass unix:/tmp/uwsgi.sock;
来自 nginx 配置?任何帮助将不胜感激。当然,如果我需要提供更多信息,请告诉我。
【问题讨论】:
-
尝试切换到一个线程而不是两个线程。不确定这是否是问题所在,但我从未打算将此服务器设为多线程,您可以通过 greenlets 获得多任务处理。
-
你发现了吗?
-
@Miguel 切换到一个线程对我有用
标签: python nginx websocket uwsgi flask-socketio