简体   繁体   中英

NodeJs server is not accessible from internet

I am new to NodeJs. I started up a simple node.js server in my local development system like this:

var http = require('http');
var fs   = require('fs');

var server = http.createServer( function (req, res) {
    console.log(req.url);
    res.end();
}).listen(8000);

I can access the server from localhost , 127.0.0.1 and 192.168.1.103 , but when I try to access the server from my public ip address 84.47.***.** only thing I am getting is:

timeout

I've been reading post about this for the past 2 hours and all just saying to set the host as 0.0.0.0 which is the default host for node.js if none is provided.

I can ping my public ip and get currect results.

I am on windows 8.1, windows firewall is off and I defined custom allow rules in comodo firewall and just to be sure even disabled the comodo firewall as well.

When I check node.js is listening on 0.0.0.0:8000 and :::8000 (IPv6 i think) for TCP connections.

What am I missing here? what should I do? is it because of windows? or what?

Appreciate any help on this.

How you connected to internet? Do you have router or not? If you have router you need to configure it for port forwarding from external IP and ports to your PC's local IP and port. And in node server you need listen your local IP (on this IP router will forward requests). If you don't have router, then you need to use your public IP for listening on your network card.

Ok figured it out my self, had nothing to do with nodejs itself(whoooops). Since i was behind a router first i had to setup port-forwarding in my router. Then even tho i had defined a rule in firewall to allow incoming connection for nodejs, but it was still blocking the incoming connections, so i had to define a rule in Global Rules to allow incoming connection for my desired port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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