简体   繁体   English

无法访问外部node.js套接字的网络

[英]Network access denied to external node.js socket

I have two servers running on Amazon's EC2. 我有两个在Amazon EC2上运行的服务器。 One is a standard web server running LAMP (this is behind an elastic load balancer), the other a Node.js server with Express and socket.io installed. 一个是运行LAMP的标准Web服务器(位于弹性负载均衡器的后面),另一个是安装了Express和socket.io的Node.js服务器。 On that Node server I have my server.js file (this file is automatically loaded on server start). 在该节点服务器上,我有server.js文件(该文件在服务器启动时自动加载)。

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(8080); 

io.on('connection', function (socket) { 
    socket.on('join', function() {
        console.log('joined');
    }
}

On the LAMP server, clients connect to this external server by: 在LAMP服务器上,客户端通过以下方式连接到该外部服务器:

<script src="https://cdn.socket.io/socket.io-1.3.4.js"></script>

var socket = io.connect('http://URL_HERE:8080');
socket.on('connect', function() {
    socket.emit('join', room_id);
});

The problem, though, is that console spits out ERR_NETWORK_ACCESS_DENIED continuously, suggesting that access to that port is blocked. 但是,问题在于控制台连续吐出ERR_NETWORK_ACCESS_DENIED ,这表明对该端口的访问已被阻止。 However, the inbound rules for the Node server are as follows: 但是,节点服务器的入站规则如下:

Custom TCP Rule -- TCP -- 8080 -- 0.0.0.0/0 (Anywhere)
HTTP            -- TCP -- 80   -- My IP
HTTPS           -- TCP -- 443  -- My IP

I have tried all sorts by more or less completely opening the inbound ports, but to no avail. 我或多或少完全打开了入站端口,尝试了各种尝试,但无济于事。 It may be worth nothing as well that the only way for people to access the client script (the LAMP server) is through a load balancer - you cannot directly access the LAMP server. 人们访问客户端脚本(LAMP服务器)的唯一方法是通过负载平衡器,这可能毫无价值,您无法直接访问LAMP服务器。 The load balancers inbound rules are as follows: 负载均衡器入站规则如下:

Custom TCP Rule -- TCP -- 8080 -- 0.0.0.0/0 (Anywhere)
HTTP            -- TCP -- 80   -- 0.0.0.0/0 (Anywhere)
HTTPS           -- TCP -- 443  -- 0.0.0.0/0 (Anywhere)

And the LAMP server's rules: 以及LAMP服务器的规则:

Custom TCP Rule -- TCP -- 8080 -- sg-elb_id
HTTP            -- TCP -- 80   -- sg-elb_id
HTTPS           -- TCP -- 443  -- sg-elb_id
... other irrelevant rules (SHH, MYSQL, ...)

Has anyone any idea why I'd be getting an access denied error? 有谁知道为什么我会得到拒绝访问错误? The Node server isn't behind the load balancer - it's in effect completely external to the process. Node服务器不在负载均衡器的后面-实际上,它完全在流程外部。 All of the security groups are not restricted in regards to outbound rules. 所有安全组的出站规则均不受限制。

Turns out the reason was it couldn't find the globally installed express or socket.io modules. 原来原因是找不到全局安装的express或socket.io模块。 Doing cd /var/www/html and then sudo npm link socket.io sudo npm link express resolved the issue. 依次执行cd /var/www/htmlsudo npm link socket.io sudo npm link express解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM