簡體   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