我正在尝试设置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;
}
通过以下方式连接wss://domain.com/
时,出现错误消息
WebSocket connection to 'wss://domain.com/' failed:
Error during WebSocket handshake: Unexpected response code: 200
那里的大多数示例都使用nodejs框架来为其站点提供服务,但是我使用的是php。
您在提供的nginx配置中将websocket端点配置为托管在/websocket
服务器内的位置,但是您尝试连接到根URL wss://domain.com
。
在升级之前,websocket连接是一个普通的HTTP(在这种情况下使用TLS包装器)会话,因此您必须确保用于访问服务的URL包括所有相关的路径指示符,例如wss://domain.com/websocket
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句