【发布时间】:2018-09-28 22:44:41
【问题描述】:
我正在尝试设置 websocket 连接 (wss)。我的域使用 ssl (certbot) 并由 Nginx 提供支持。我不确定如何配置我的/etc/nginx/sites-available/example.com 文件。
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
...
}
我将以下内容添加到我的配置块中:
location /websocket {
proxy_pass https://example.com;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
当通过wss://example.com/ 连接时,我收到一个错误
WebSocket connection to 'wss://example.com/' failed:
Error during WebSocket handshake: Unexpected response code: 200
那里的大多数示例都使用 nodejs 框架来服务他们的网站,但我使用的是 php。有没有可以指导我的教程,或者有没有人知道如何配置我的配置文件?谢谢!
【问题讨论】: