我正在尝试使用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配置文件中获取吗?非常感谢您的帮助。当然,如果需要提供更多信息,请告知。