我正在尝试建立一个websocket连接(wss)。我的域名使用ssl (certbot),由Nginx提供动力。我不知道如何配置我的/etc/nginx/sites-available/domain.com文件。
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
...
}我在配置块中添加了以下内容:
location /websocket {
proxy_pass https://domain.com;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}当连接via:wss://domain.com/时,我收到一个错误
WebSocket connection to 'wss://domain.com/' failed:
Error during WebSocket handshake: Unexpected response code: 200这里的大多数例子都是使用nodejs框架为他们的站点服务,但我使用的是php。
发布于 2018-09-28 21:30:28
websocket端点是在提供的nginx配置中配置的,该配置位于服务器内的/websocket位置,但您正在尝试连接到根URL wss://domain.com。
websocket连接是一个普通的HTTP (在本例中是带有TLS包装器的)会话,直到进行升级,所以您必须确保用于访问服务的URL包括所有相关的路径指示符,例如wss://domain.com/websocket。
https://unix.stackexchange.com/questions/472162
复制相似问题