我将下面的nginx.conf文件设置为处理http和https。 我目前正在使用自签名证书来testingssl。
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; }
当我尝试通过本地连接。 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?
如果你的连接是443? 例如wss:// localhost:443 / socketcluster /。
端口80未configuration为ssl,因此不会响应ssl握手。
同样地(如这里 ),您可以直接调用,而不指定端口(默认端口80和443),例如wss:// localhost / socketcluster /。