简体   繁体   English

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

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

I'm running a "hello world" http server using node.js on Fedora 20. 我正在Fedora 20上使用node.js运行“ hello world” http服务器。

I can see "hello world" using my Firefox by typing any of the following in my address bar: 192.168.2.85, localhost, 0.0.0.0, 192.168.122.1 通过在地址栏中键入以下任意内容,我可以使用Firefox查看“ hello world”:192.168.2.85,localhost,0.0.0.0、192.168.122.1

I thought I would be able to open a browser on my wife's computer when she's connected to the same DCHP NAT router, type 192.168.2.85 in the address bar, and see "hello world". 我想当妻子连接到同一个DCHP NAT路由器时,我可以在她的计算机上打开浏览器,在地址栏中键入192.168.2.85,然后看到“ hello world”。

However, her Chrome33 says "This webpage is not available" or "Oops! ...could not connect to 192.168.2.25." 但是,她的Chrome33说“此网页不可用”或“糟糕!...无法连接到192.168.2.25”。 Her IE9 says "...cannot display the webpage." 她的IE9说“ ...无法显示该网页。” But from her command prompt I can ping 192.168.2.85. 但是从她的命令提示符下,我可以ping 192.168.2.85。

On her computer (Windows 7), I tried turning off Windows Firewall and turning off antivirus. 在她的计算机(Windows 7)上,我尝试关闭Windows防火墙并关闭防病毒功能。

On my computer, I tried 在电脑上,我尝试

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

On our microsoft router, I tried Persistent Port Forwarding (inbound port range 80-80, private port range 80-80, type TCP, Private ip 192.168.2.85) and Enable virtual DMZ for 192.168.2.85. 在我们的Microsoft路由器上,我尝试了永久端口转发(入站端口范围80-80,专用端口范围80-80,键入TCP​​,专用ip 192.168.2.85)并为192.168.2.85启用了虚拟DMZ。 (I hope I'm not giving enough info to allow an attack?) I saw no reference to WDS in my router. (我希望我没有提供足够的信息来允许攻击?)我在路由器中没有看到对WDS的引用。

what should I do to make my node.js app available to other computers in my home? 如何使我的node.js应用程序可用于家中的其他计算机? I'm new to all this. 我是这一切的新手。

Here's some more details . 这里有更多细节。 . .

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...");

I've looked at: Cannot browse site hosted on local machine from a mobile 我看过: 无法通过移动设备浏览本地计算机上托管的网站

Node.js connect only works on localhost Node.js连接仅适用于本地主机

How do I run Node.js on port 80? 如何在端口80上运行Node.js?

connecting to node.js http server on linux machine from windows machine 从Windows机器连接到Linux机器上的node.js http服务器

Node.JS Not working on the internet Node.JS无法在Internet上运行

and others. 和别的。

If you have a Linux server without a GUI, you can set up the firewall manually using the firewall-cmd command... 如果您的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

That's it. 而已。 Hope this helps someone. 希望这对某人有帮助。

First, I added a zone line to the ifcfg file for the home network. 首先,我在家庭网络的ifcfg文件中添加了一个区域行。

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

Then I rebooted to ensure change took place. 然后我重新启动以确保进行了更改。 Then in terminal I typed 然后在终端输入

firewall-config

It opens in the public zone, which is default, and allows the administrator to select trusted services. 它在默认的公共区域中打开,并允许管理员选择受信任的服务。 (If I get 10 reputation points I can include my screenshot here.) (如果我获得10点声望,则可以在此处包括我的屏幕截图。)

If the ZONE is not set in ifcfg as above, then selecting the (public) http checkbox will still work. 如果未在上述ifcfg中设置ZONE,则仍然可以选择(公共)http复选框。

But if ZONE=internal in the ifcfg file, then click on internal zone and select http there, for the added security. 但是,如果ifcfg文件中的ZONE = internal,则单击内部区域并在其中选择http,以提高安全性。 (Or I could have used ZONE=home or ZONE=work or ZONE=trusted. Same idea.) The change is immediately applied. (或者我可以使用ZONE = home或ZONE = work或ZONE = trusted。相同的想法。)更改将立即应用。 The other computer's browser could see my "hello world". 另一台计算机的浏览器可以看到我的“ hello world”。

Finally, at the top, I changed Runtime to Permanent from the dropdown list and closed the window. 最后,在顶部,我从下拉列表中将Runtime更改为Permanent并关闭了窗口。

I had thought I was accomplishing the same thing earlier when I tried iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT so I guess I need to look into what the difference is. 我以为我在尝试iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT时会完成相同的事情,所以我想我需要研究一下两者之间的区别。

Thanks to jfriend00 for pointing me in the right direction. 感谢jfriend00向我指出正确的方向。 (If I had reputation I would upvote your comment.) (如果我有声誉,我会反对你的评论。)

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

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