How to configure Nginx server for Flask-Sock?

91 views Asked by At

I am not talking about Socket-IO but just regular Websocket, I am using this library: https://flask-sock.readthedocs.io/en/latest/web_servers.html

How do I configure my Nginx configuration for wss://? I currently have set up cerbot and the unix service to always start my Gunicorn Flask app. My websocket endpoints worked fine before I got into Nginx where I just used port 5000, but now I get 400 BAD REQUEST because I believe Nginx is not configured for Websocket.

1

There are 1 answers

0
Jiehfeng On

I was following the guide on Flask-SocketIO and it never worked for me but I found out why, I had to stop and start nginx, then stop and start and then enable my webserver. Only THEN it worked.

This is all that was needed to add to the configuration after the first two lines inside location:

location / {
    include proxy_params;
    proxy_pass http://unix:/root/example/example.sock;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
}