【问题标题】:WebSockets with nginx + uwsgi + flask-socketio使用 nginx + uwsgi + flask-socketio 的 WebSockets
【发布时间】: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


【解决方案1】:

您应该将uwsgi_pass unix:/tmp/uwsgi.sock; 更改为uwsgi_pass unix:///tmp/uwsgi.sock;

【讨论】:

    猜你喜欢
    • 2019-09-27
    • 2017-11-16
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 2023-03-06
    • 2016-05-24
    • 2023-02-09
    • 1970-01-01
    相关资源
    最近更新 更多