Deploy Flask socketio on Linode

Hello Linode community.
I developed a flask web application on my local host. The application includes chatroom functionality which I implemented using flask-socketio. The application works fine on localhost. Last week I deployed my flask application on Linode and socket functionality is not working.
Here are the configuration diff between my localhost and Linode:

  1. In Linode, I don't use the following command "socketio.run(app,host="0.0.0.0",allow_unsafe_werkzeug=True,debug=True, use_reloader=False)". Instead, I added "import run" to init__.py file. (the socketio.run command is in the __main of run.py).

  2. I configure nginx file as follow:
    *server {
    listen 80;
    server_name 172.232.56.254;

    location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /socket.io {
    include proxy_params;
    proxy_http_version 1.1;
    proxy_buffering off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass http://127.0.0.1:5000/socket.io;
    }
    }*

When I load the application I don't get errors on the server side. But on my client I get 502 bad gateway.
Example:
Request URL: http://172.232.56.254/socket.io/?EIO=4&transport=polling&t=OeNgJ4M Request Method: GET Status Code: 502 Bad Gateway Remote Address: 172.232.56.254:80 Referrer Policy: strict-origin-when-cross-origin

Any idea how to fix this?

Tomer

1 Reply

I managed to fix the problem.
As per flask-socketio documentation,

I default back to standard nginx configuration (remove socket.io section).

I'm running my application using:
"gunicorn -k gevent -w 1 <my module="">:app"</my>

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct