1

I cannot connect to my Socket IO server after uploading and configuring on the server. It is giving 400 error:

Error: Unexpected server response: 400 enter image description here

My server: Rocket Linux. Using Nginx. Socket Io server was written in Python. In my localhost it is working perfectly. However, on the server which I should configure it is giving above error. Even, I configured on different server with same Nginx configuration, it was successfully connected. My Nginx config:

server {
        listen 5000 ssl;
        server_name  e-buyurtma.ecdn.uz  www.e-buyurtma.ecdn.uz;

        access_log      /var/log/nginx/ws-server-access.log;
        error_log       /var/log/nginx/ws-server-error.log;

        location ^~/socket.io {
            proxy_pass http://127.0.0.1:3675;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $host;
        }

        ssl_certificate                 hidden;
        ssl_certificate_key             hidden;
        ssl_protocols                   TLSv1.2 TLSv1.1 TLSv1;
        ssl_ciphers                     hidden;
        ssl_prefer_server_ciphers       on;
        ssl_dhparam                     hidden;
        ssl_session_timeout             5m;

}

Nginx error logs: enter image description here Python server logs: enter image description here

  • 1
    Looks at the logs for the Python server for additional clues. – Miguel Grinberg Jul 20 '23 at 22:47
  • Hello, "Invalid websocket upgrade " this error appearing in the python server logs. I have added screenshot of the log on the question as edit. – Ahror Gaibnazarov Jul 21 '23 at 05:30
  • 1
    Does your server have a different web server? "Invalid websocket upgrade" means the web server doesn't support web sockets. – Tim Roberts Jul 21 '23 at 05:41
  • We are using Nginx/1.20.1 as a web server. If you meant another thing, I can check it. Thank you, for trying to help! – Ahror Gaibnazarov Jul 21 '23 at 05:51
  • Additionally, I can say, requests from internet comes to our server through another proxy server. I thought, maybe something related to firewall rules or something like that after a bit searching forums. – Ahror Gaibnazarov Jul 21 '23 at 05:52

1 Answers1

0

The problem was solved! There was one proxy Ubuntu server behind the server I run my websocket server. In that proxy Ubuntu server, redirection to my server was done by Nginx. We have added socket IO's header configs to that proxy server's Nginx, then my requests worked successfully.

location / {
    proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "Upgrade";
      proxy_set_header Host $host;
}