我在我的网站上使用AutobahnJS和Thruway,使用非加密连接一切正常:
var connection = new autobahn.Connection({
url: 'ws://www.example.com:9090',
realm: 'restricted_realm'
});
connection.onopen = function (session) {
alert('yay');
};
connection.open();
但是,我无法使用安全连接。将ws://www.mysite.com:9090
更改为wss://www.example.com:9090
会在控制台中导致此错误:
与'wss://www.example.com:9090 /'的WebSocket连接失败:连接建立错误:net :: ERR_TIMED_OUT
我的服务器上有SSL证书,可以通过https://www.example.com
访问我的网站。
我需要做些什么来使安全的websockets工作?
答案 0 :(得分:2)
答案 1 :(得分:1)
I use HAProxy 1.5+ for SSL termination. Here is part of my config from production.
frontend public
# HTTP
bind :80
# Redirect all HTTP traffic to HTTPS
redirect scheme https if !{ ssl_fc }
# HTTPS
bind :443 ssl crt ssl.pem no-sslv3 ecdhe prime256v1 ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
acl is_websocket hdr(Upgrade) -i WebSocket
use_backend ws if is_websocket #is_websocket_server
default_backend www
backend ws
server ws1 127.0.0.1:9090
backend www
timeout server 30s
server www1 127.0.0.1:8080
In my configuration, Apache listening for unencrypted traffic on port 8080 and WebSocket server listening unencrypted traffic on port 9090