A
A
Alexey Poloz2019-03-08 15:45:17
Nginx
Alexey Poloz, 2019-03-08 15:45:17

NGINX + Gunicorn + Socket.IO (Flask-SoketIO) How to setup config file?

I have a Flask web application using Socket.IO (Flask-SocketIO).
Now I have Flask configured to work through Gunicorn with NGINX. It works. Except for Socket.IO requests. How to set it up?
If I configure Socket.IO via unix:myproject.sock there will be a huge delay. I found that this is done with a special command:

gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --bind unix:app.sock -m 007

But in that case, how do I leave regular requests to Flask?
My configs:
/etc/nginx/sites-available/myproject

server {
    listen 80;
    server_name blabla.org www.blabla.org;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/tensy/blend/myproject.sock;
    }

  location ~* \.io {
      ???
      # Это не работает: proxy_pass http://unix:/home/tensy/blend/myproject.sock;
      proxy_redirect off;

      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }

/etc/systemd/system/myproject.service

[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=tensy
Group=www-data
WorkingDirectory=/home/tensy/blend
Environment="PATH=/home/tensy/blend/flask/bin"
ExecStart=/home/tensy/blend/flask/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question