unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.45k stars 687 forks source link

Nginx + uWSGI + SocketIO support #1584

Open Paradoxis opened 7 years ago

Paradoxis commented 7 years ago

I'm currently building an app that requires SocketIO support, I've read on the documentation that uWSGI has support for WebSockets, however I've only managed to get it working through using the proxy_pass directive which doesn't use the binary protocol, this is my current setup.

Do you happen to know how I could get the binary protocol to work with SocketIO? I checked StackOverflow but nobody seemed to know. I've read in some places that uWSGI doesn't play well with SocketIO (source), is this true? Thanks!

Nginx config

server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name _;
    server_tokens off;

    location / {
        include uwsgi_params;
        proxy_pass http://unix:/home/user/project/server.sock;
    }

    location /socket.io/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://unix:/home/user/project/server.sock;
    }
}

uWSGI config (ini)

# Configuration file for Nginx
[uwsgi]
module = wsgi:app
master = true
processes = 5
buffer-size=32768
http-websockets = true
socket = server.sock
chmod-socket = 666
vacuum = true
die-on-term = true
logto = /var/log/uwsgi/%n.log

My code (Flask, Flask-SocketIO)

from flask import Flask
from flask_socketio import SocketIO, emit

server = Flask(__name__)
io = SocketIO(server)

@server.route("/")
def index():
    return server.send_static_file("index.html")

@io.on("x")
def ping():
    emit("y")

Sources:

jacobthetechy commented 7 years ago

Would also like some help / guidance with this. Will be needing a solution to this problem soon.

dpq commented 6 years ago

@Paradoxis have you managed to make your setup work?