当我尝试建立一个wss
与我的服务器的连接:
与“wss://mydomain:3000/”的 WebSocket 连接失败:错误
连接建立:net::ERR_CONNECTION_CLOSED
我目前有一个 apache2 虚拟主机配置设置来侦听端口 443 和 80 上的请求:
<VirtualHost *:80>
ServerName otherdomainname.co.uk
ServerAlias www.otherdomainname.co.uk
RewriteEngine On
RewriteRule ^/(.*)$ /app/$1 [l,PT]
JkMount /* worker2
</VirtualHost>
<VirtualHost _default_:443>
ServerName otherdomainname.co.uk
ServerAlias www.otherdomainname.co.uk
RewriteEngine On
RewriteRule ^/(.*)$ /app/$1 [l,PT]
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
<Location />
SSLRequireSSL On
SSLVerifyClient optional
SSLVerifyDepth 1
SSLOptions +StdEnvVars +StrictRequire
</Location>
JkMount /* worker2
</VirtualHost>
正如您所看到的,它使用 JkMount 将请求传递给 Tomcat,Tomcat 在 HTTP 和 HTTPS 上都能正确地提供网页。
当我在端口 80 上使用 HTTP 协议访问该站点时,可以使用以下命令建立 WebSocket 连接:ws
协议。
当我在端口 443 上使用 HTTPS 协议访问该站点时,该站点服务正常,但未使用以下命令建立 WebSocket 连接wss
.
我使用“ws”node.js 模块来提供 WebSocket 服务器:
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ port: 3000 }),
fs = require('fs');
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
ws.send(message);
ws.send('something');
});
为什么我无法使用以下命令成功连接到 WebSocket 服务器wss
协议结束https
?