1

I have a flask-app which is using flask-socketio extension. It works fine on local machine using 'socketio.run()' or 'flask run' dev server. I want to make it work with a nginx proxy, and it works on local machine with this nginx server config:

file /etc/nginx/sites-available/server.conf

server {
    listen 8080;
    location / {
        proxy_pass http://localhost:5000;
    }
}

The actual app is running on port 5000 with socketio.run(), which as i heard is also a good production server. The strange thing is that it works even with this message: "WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance." It also works with this warning: "Flask-SocketIO is Running under Werkzeug, WebSocket is not available." (first when i use socketio.run(), second with flask run)

Yet if I try to run the same thing on the production server, only http part works, and sockets don't. As i read everywhere on the Internet I should specify headers Connection and Upgrade in nginx server config which i do not understand why and which i tried too:

file /etc/nginx/sites-available/server.conf

server {
        listen 80;
        server_name servername.com;

        location / {
            proxy_pass http://127.0.0.1:5000;
        }

        location /socket.io/ {
            proxy_pass http://127.0.0.1:5000/socket.io;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
}

Result is the same, sockets are not working. Using 'flask run' with any of configs i get these debug messages: 127.0.0.1 - - [04/Feb/2019 20:55:52] "GET /socket.io?EIO=3&transport=polling&t=MYwIxxF HTTP/1.1" 404 - The indicate not working socketio, yet the server gets it and replyes with 404, which i see no reason for.

My local computer runs Kali linux and nginx 1.13.12, remote is Ubuntu 18.04 with nginx 1.14.0 Right now I really don't understand which configuration is proper, why is the first configuraion working on my local machine and why none of configurations work on production server and how do i interpreter this 404 message. Even though there are several guides on the Internet, it doesn't work with me.

Any help appreciated!

user87035
  • 11
  • 3
  • Can you confirm that socket.io is installed on the production server? The 404 error is indicating that the server can't find the file, or at least not at the specified location. – tshimkus Feb 05 '19 at 00:11

1 Answers1

-1

Maybe nginx was unable to match /socket.io/ location to /socket.io?EIO=3&transport=polling&t=MYwIxxF path. Take a look at nginx documentation on location to find out how you can write location matcher that fits your needs.

Fine
  • 2,114
  • 1
  • 12
  • 18