【发布时间】:2015-02-02 15:13:14
【问题描述】:
我无法在生产环境中连接到 socket.io。它在我的开发服务器中运行良好,但我没有在生产中的控制台中收到“websocket 用户已连接”消息,并且我的热图没有填充测试数据。我在浏览器 jscript 控制台中得到 net::ERR_CONNECTION_TIMED_OUT。
来自服务器:
io.origins('http://example.com/path:8080')
app.get('/somepath', function (req, res, next) {
// code here
io.emit('update', data)
console.log('update has been emitted') // this prints and I see the data object in the console
res.end("OK")
})
io.on('connection', function (socket) {
console.log('websocket user connected')
});
来自角度控制器:
$http.get('http://example.com/somepath?'+str) // hits somepath with test data in query string 'str'
来自 /path 中的脚本:
var socket = io('http://example.com:8080');
我还在页面 /path 中包含了 socket.io 的 cdn
<script src="https://cdn.socket.io/socket.io-1.3.2.js"></script>
【问题讨论】:
-
检查你的防火墙。
-
@Alexander 我该怎么做?这是一个远程 ubuntu 服务器,我知道我将 ip 表设置为将端口 8080 路由到 80。这是你的意思吗?因为我可以访问网站上的网页和其他html页面,但是无法进行websocket连接。
-
如果您的 web socket 绑定到内部端口 8080,并且您的 iptables 将外部端口 8080 流量路由到端口 80,则请求不会到达 socket.io,它只会到达 webserver。尝试使用与您的开发服务器相同的环境设置。
-
@Alexander 我的设置与我的开发服务器相同。他们所有人的端口都是3002。我不确定您的意思是“如果您的 Web 套接字绑定到内部端口 8080,并且您的 iptables 将外部端口 8080 流量路由到端口 80,则请求不会到达 socket.io,它只会到达 webserver。”我将外部流量设置为路由到 80,我认为这是 HTTP 流量的默认端口,但我从未在 iptables 中专门为 websockets 设置任何内容。我是否需要指定另一个端口来将任何使用 ws 协议的东西路由到?