【发布时间】:2018-04-26 15:03:21
【问题描述】:
我正在尝试使用 apache 设置代理,以便能够在我的 nodejs 应用程序中使用 socket.io。但我在客户端收到此错误消息:
WebSocket connection to 'wss://example.com/tools/socket.io/?EIO=3&transport=websocket&sid=eOGwJSC14TTWhHRMAAAR' failed: Error during WebSocket handshake: Unexpected response code: 400
这是我的 apache 配置:
<VirtualHost *:443>
ServerName example.com
ServerAlias example.com
#SSLRequireSSL
SSLProtocol all -SSLv2 -SSLv3
SSLCompression off
SSLHonorCipherOrder on
SSLEngine on
SSLCertificateFile /etc/ssl/main.pem
SSLCertificateKeyFile /etc/ssl/dec_ssl.key
SSLCertificateChainFile /etc/ssl/sub.class1.server.ca.pem
SSLCACertificateFile /etc/ssl/main.pem
SSLProxyEngine On
ProxyPreserveHost On
ProxyRequests off
</VirtualHost>
<Location /tools/>
ProxyPass http://localhost:8181/
ProxyPassReverse http://localhost:8181/
</Location>
这是客户端代码:
socket = io.connect("https://example.com",{path:'/tools/socket.io'});
socket.on("connect", function () {
console.log("socketio Connected to server!");
});
我还需要在 apache 配置中添加什么来消除此错误?
编辑:我的 apache 版本:服务器版本:Apache/2.4.6 (CentOS)
【问题讨论】:
-
你确定你的 socket.io 服务器正在监听 8181 吗?能直接打吗?
-
你检查过你的 Apache 错误日志吗?
-
@M.Babcock,是的,服务器在 8181 上运行。我能够从 url 获取 socket.io.js:example.com/tools/socket.io/socket.io.js
-
在不使用 apache 的情况下使用 nginx + nodejs 时收到确切的错误消息