我在我的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