繁体   English   中英

无法通过内部/专用网络上的浏览器使用Node.js http服务器

[英]Node.js http server not available via browser on internal/private network

我正在Fedora 20上使用node.js运行“ hello world” http服务器。

通过在地址栏中键入以下任意内容,我可以使用Firefox查看“ hello world”:192.168.2.85,localhost,0.0.0.0、192.168.122.1

我想当妻子连接到同一个DCHP NAT路由器时,我可以在她的计算机上打开浏览器,在地址栏中键入192.168.2.85,然后看到“ hello world”。

但是,她的Chrome33说“此网页不可用”或“糟糕!...无法连接到192.168.2.25”。 她的IE9说“ ...无法显示该网页。” 但是从她的命令提示符下,我可以ping 192.168.2.85。

在她的计算机(Windows 7)上,我尝试关闭Windows防火墙并关闭防病毒功能。

在电脑上,我尝试

iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

在我们的Microsoft路由器上,我尝试了永久端口转发(入站端口范围80-80,专用端口范围80-80,键入TCP​​,专用ip 192.168.2.85)并为192.168.2.85启用了虚拟DMZ。 (我希望我没有提供足够的信息来允许攻击?)我在路由器中没有看到对WDS的引用。

如何使我的node.js应用程序可用于家中的其他计算机? 我是这一切的新手。

这里有更多细节。

netstat -ntlp
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4566/node   


cat test.js
var http = require("http");

var app = http.createServer(function(request, response) {
  response.writeHead(200, {
    "Content-Type": "text/plain"
  });
  response.end("hello world\n");
});

app.listen(80); //192.168.2.85  
console.log("Server running...");

我看过: 无法通过移动设备浏览本地计算机上托管的网站

Node.js连接仅适用于本地主机

如何在端口80上运行Node.js?

从Windows机器连接到Linux机器上的node.js http服务器

Node.JS无法在Internet上运行

和别的。

如果您的Linux服务器没有GUI,则可以使用firewall-cmd命令手动设置防火墙。

# list current settings prior to changes; this is your baseline
firewall-cmd --zone=internal --list-all

# add the http services (https is optional based on your needs)
firewall-cmd --zone=internal --add-service=http
firewall-cmd --zone=internal --add-service=https

# I am using port 8080 with node.js just to differentiate it (optional)
firewall-cmd --zone=internal --add-port=8080/tcp

# the zone 'public' is the default zone on my machine but it is not
# associated with the eth0 network adapter.  however, the zone 'internal' is,
# therefore, make 'internal' the default zone
firewall-cmd --set-default-zone=internal

# make the changes permanent so that they are present between reboots
firewall-cmd --runtime-to-permanent

# reload all of the firewall rules for good measure
firewall-cmd --complete-reload

# list out the current settings after changes
firewall-cmd --zone=internal --list-all

而已。 希望这对某人有帮助。

首先,我在家庭网络的ifcfg文件中添加了一个区域行。

# vi /etc/sysconfig/network-scripts/ifcfg-<router-ssid-name>   
    . . . 
    ZONE=internal

然后我重新启动以确保进行了更改。 然后在终端输入

firewall-config

它在默认的公共区域中打开,并允许管理员选择受信任的服务。 (如果我获得10点声望,则可以在此处包括我的屏幕截图。)

如果未在上述ifcfg中设置ZONE,则仍然可以选择(公共)http复选框。

但是,如果ifcfg文件中的ZONE = internal,则单击内部区域并在其中选择http,以提高安全性。 (或者我可以使用ZONE = home或ZONE = work或ZONE = trusted。相同的想法。)更改将立即应用。 另一台计算机的浏览器可以看到我的“ hello world”。

最后,在顶部,我从下拉列表中将Runtime更改为Permanent并关闭了窗口。

我以为我在尝试iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT时会完成相同的事情,所以我想我需要研究一下两者之间的区别。

感谢jfriend00向我指出正确的方向。 (如果我有声誉,我会反对你的评论。)

暂无
暂无

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

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