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:
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).
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
3 Replies
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>
Hi, I've watched 2 tutorials showing how to deploy a Flask app, but I always get an error related to websockets, how did you manage to deploy yours?
These are the tutorials I've watched:
https://www.youtube.com/watch?v=YFBRVJPhDGY&t=133s&ab_channel=TechWithTim
https://www.youtube.com/watch?v=goToXTC96Co&pp=ygUaZGVwbG95IGZsYXNrIGNvcmV5IHNjaGFmZXI%3D
Hi there @yuvalamda, I tried to research this for you, but I wasn't able to find much without knowing a specific error. You may want to check out the flask-socket.io troubleshooting page.
If that doesn't help, you might consider tryin to Ask a new Question which may get seen more people . I recommend the post about Asking Good Questions to see what kind of information to share in your post for best results.