WebSocket与'wss:// io /?EIO = 3&transport = websocket'的连接失败:WebSocket握手期间出错:意外的响应代码:404

时间:2019-04-18 14:28:19

标签: reactjs ssl nginx websocket socket.io

我在我的react组件中使用此代码进行套接字连接。

var socket = io(Config.SOCKET_URL, { transports: ['websocket'] });
socket.on('connect', function(){ console.log("socket connected"); });

这是我的nginx文件

server {
    listen 80;
    server_name SITE_URL;
    client_max_body_size 128m;
    return 301 SITE_URL$request_uri;
}

server {
    listen 443;
    ssl on;
    ssl_certificate /var/www/chain.crt;
    ssl_certificate_key /var/www/private.key;
    server_name SITE_URL;
    client_max_body_size 128m;
    location / {
        proxy_pass http://IP:PORT;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_redirect off;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_redirect off;
    }
}

但是不幸的是,我的套接字无法连接到服务器端点。

这是我遇到的错误

WebSocket connection to 'wss://io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 404

0 个答案:

没有答案