Amy T McBride Amy T McBride - 5 months ago 16
Node.js Question

Webpage not publicly accessible via port 80

I have the following code written with Node/Koa, which is serving to

port 80
:

const
koa = require('koa'),
route = require('koa-route'),
network = koa(),
common = require('koa-common'),
PORT = 80;

// enable logger middleware
network.use(common.logger('dev'));

// enable static middleware
network.use(common.static(__dirname + '/public'));

network.use(route.get('/', index));
network.use(route.get('/about', about));
function *index() {
this.body = "<h1>Is this message on my computer, or on yours...?</h1>";
}
function *about() {
this.body = "<h2>How about now...</h2>";
}
var server = network.listen(PORT, function () {
console.log('Listening on port %d', server.address().port);
});


I have reserved an address (
168.192.1.91
) for the host computer, set up port forwarding to this address on
port 80
, made an exception in the Windows 10 firewall for
port 80
when connected to via any protocol, and tested with You Get Signal:

Port Forwarding Tester

which confirms that the port is currently open. When I browse to
localhost:80
I can see the default page. However, when I type the computer's public IP address into the browser (I'm typing in the one that I've partially obscured, which I believe should be the correct one):

IP Address

this page fails to load with the following error:

This site can’t be reached

109.[...] took too long to respond.
Try:
Reloading the page
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_TIMED_OUT


and there is no activity in the Koa log (which logs fine when I browse to there via
localhost:80
). Any ideas what could be blocking the connection?

I have also tried adding the host address as a second parameter like this:

const HOST = "127.0.0.1";

var server = network.listen(PORT, HOST, function () {
console.log('Listening on port %d', server.address().port);
});


This works for the loopback address, but when I specify my public IP I get this error:

C:\Sites\order-server>node --harmony cheese.js
events.js:154
throw er; // Unhandled 'error' event
^

Error: listen EADDRNOTAVAIL [My public IP here]:80
at Object.exports._errnoException (util.js:890:11)
at exports._exceptionWithHostPort (util.js:913:20)
at Server._listen2 (net.js:1221:19)
at listen (net.js:1270:10)
at net.js:1379:9
at _combinedTickCallback (node.js:386:13)
at process._tickCallback (node.js:407:11)
at Function.Module.runMain (module.js:449:11)
at startup (node.js:142:18)
at node.js:939:3

Answer

Maybe koa by default only binds to 127.0.0.1 so you can try binding to any host explicitly with .listen(80, '0.0.0.0')

Otherwise if the firewall ant the port forwarding is configured accordingly, the problem could be that your Internet Provider is blocking incoming connections somewhere. You could try useing an Port over 1024, if it only blocks Ports below.

Comments