I use socket. io to implement websocket, which can connect normally in the development environment. Both the front-end and back-end are deployed to the production environment, but the connection using wss failed.
WebSocket connection to 'wss://xxxxx:7171/socket.io/?EIO=4&transport=websocket' failed:
连接失败 Error: websocket error
at a5.onError (index-5d19907a.js:12:36135)
at ws.onerror (index-5d19907a.js:12:42813)
Currently, I can run normally in the local Windows development environment. However, when both the frontend and backend are deployed to the server, the WebSocket connection fails. I have placed the business code and WebSocket code in the same NestJS backend project because I want to access the data through port 1216, which is currently working fine. However, the WebSocket connection fails. I have configured the server's proxy settings, but it has not resolved the issue. If the information I provided is incomplete, feel free to ask me for more detailed configuration information.
Describe the bug
I use socket. io to implement websocket, which can connect normally in the development environment. Both the front-end and back-end are deployed to the production environment, but the connection using wss failed.
To Reproduce
Please fill the following code example:
Socket.IO server version:
4.6.1
Server
Socket.IO client version:
4.6.1
Client
Main.ts
Nginx
Expected behavior
Successfully connected using wss
Platform:
Additional context
Currently, I can run normally in the local Windows development environment. However, when both the frontend and backend are deployed to the server, the WebSocket connection fails. I have placed the business code and WebSocket code in the same NestJS backend project because I want to access the data through port 1216, which is currently working fine. However, the WebSocket connection fails. I have configured the server's proxy settings, but it has not resolved the issue. If the information I provided is incomplete, feel free to ask me for more detailed configuration information.