无法连接到Socket IO服务器 (400错误)

huangapple go评论69阅读模式
英文:

Cannot connect to Socket IO server (400 error)

问题

我无法连接到我的Socket IO服务器,尽管在服务器上上传和配置了它。它返回400错误:

> 错误:意外的服务器响应:400
无法连接到Socket IO服务器 (400错误)

我的服务器:Rocket Linux。使用Nginx。Socket Io服务器是用Python编写的。在我的本地主机上,它运行得很完美。然而,在我应该配置它的服务器上,它返回了上述错误。即使我在具有相同Nginx配置的不同服务器上进行了配置,也能成功连接。
我的Nginx配置:

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错误日志:
无法连接到Socket IO服务器 (400错误)

Python服务器日志:
无法连接到Socket IO服务器 (400错误)

英文:

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
无法连接到Socket IO服务器 (400错误)

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:
无法连接到Socket IO服务器 (400错误)
Python server logs:
无法连接到Socket IO服务器 (400错误)

答案1

得分: 0

问题已解决!在运行我的WebSocket服务器的服务器后面有一个代理Ubuntu服务器。在那个代理Ubuntu服务器上,通过Nginx进行了对我的服务器的重定向。我们已将Socket IO的头配置添加到该代理服务器的Nginx配置中,然后我的请求成功运行。

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

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;
}

huangapple
  • 本文由 发表于 2023年7月20日 17:30:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728502.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定