![无法通过 wss 连接到服务器](https://linux22.com/image/688811/%E6%97%A0%E6%B3%95%E9%80%9A%E8%BF%87%20wss%20%E8%BF%9E%E6%8E%A5%E5%88%B0%E6%9C%8D%E5%8A%A1%E5%99%A8.png)
我将下面的 nginx.conf 文件设置为处理 http 和 https。我目前正在使用自签名证书通过 ssl 进行测试。
server {
listen 80;
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
location / {
proxy_pass http://node:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /socketcluster/ {
proxy_pass http://node:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
当我尝试通过 localhost 连接时,http、https 和 ws:// 似乎工作正常。但是,当客户端尝试通过 wss:// 连接时,我收到以下错误
WebSocket connection to 'wss://localhost:80/socketcluster/' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR
我的 nginx 日志显示了这一点 -
nginx | 172.18.0.1 - - [25/Aug/2016:20:34:51 +0000] "\x16\x03\x01\x00\x7F\x01\x00\x00{\x03\x02\xB0\x80r\xEEH\x8C\x03\xAFFw\x9A4\xC2\x84\xB6\xD9\x9E;|\xDFbD\x1D\xF6)Ai\xB3<C\x13O\x00\x00\x10\xC0" 400 173 "-" "-"
Is there something additional i have to be adding to the nginx conf file to get wss:// to work?
答案1
您的连接是否应该为 443?例如 wss://localhost:443/socketcluster/。
端口 80 未配置为 ssl,因此不会响应 ssl 握手。
同样(如这里)您可以直接调用而不指定端口(默认端口 80 和 443)例如 wss://localhost/socketcluster/。