【发布时间】:2018-03-25 08:50:14
【问题描述】:
我正在尝试在我的服务器中部署来自 official sample 的节点 js socket.io 项目(带有 Apache 2 服务器的 Ubuntu)
这是我在/etc/apache2/sites-available/000-default.conf中的代理设置
ProxyPass /ChatSocket http://localhost:3000
ProxyPass /socket.io http://localhost:3000/socket.io
ProxyPass /socket.io ws://localhost:3000/socket.io
但是当我尝试通过 dns 访问我的 Web 服务器时,我无法连接到套接字。
我的浏览器控制台出现此错误
WebSocket connection to 'ws://example.com/socket.io/?EIO=3&transport=websocket&sid=HgU6py-fCl1GFrdsAAAK' failed: Error during WebSocket handshake: Unexpected response code: 400
可能是因为 url http://example.com/socket.io 与 ws://example.com/socket.io 冲突
如何使用同一个 url 的 websocket 和 http?因为似乎http://example.com/socket.io和ws://example.com/socket.io是socket.io从这一行生成的
var server = require('http').createServer(app);
var io = require('socket.io')(server);
是否有任何其他解决方法来解决此问题,或者在没有 proxypass 的情况下将我的 socket.io 节点 js 应用程序部署到我的 apache 服务器中?
【问题讨论】:
标签: javascript node.js apache ubuntu socket.io