6

So I have a web application being run on an http-server via npm. In my package.jsonfile, I have the line "start": "sudo http-server -a [my ip address] -p 8065 -c-1", and my app runs fine when I go to http://myipaddress:8065. However if I change the 8065 to just 80, in the json file (which is what I want), I still get the success message:

Starting up http-server, serving ./
Available on:
http://myipaddress:80

But when I go to the link, chrome givess me an ERR_CONNECTION_REFUSED. Anybody know what's going on?

rohan
  • 129
  • 2
  • 17

5 Answers5

4

I would suggest there are three possible problems here.

  1. Port 80 is already in use.
  2. You are not running the application as root (you can't bind to ports <1024 if you are not root)
  3. http-server isn't binding correctly

To check if port 80 is already in use try

netstat -lntu | grep :80

If port 80 is already in use you should see something like

tcp6       0      0 :::80                 :::*                    LISTEN

You will need to close whatever is running on port 80 (apache? nginx?)


To check if you can actually bind to port 80, try running http-server from the console rather than via npm i.e.

sudo http-server -a [my ip address] -p 80 -c-1

If the above works you should be able to run npm as root to start your http-server i.e.

sudo npm start

You may need to remove sudo from your package.json:

"start": "http-server -a [my ip address] -p 8065 -c-1"

We need to make sure that http-server is working correctly on your system. We will test it with w3m a console based web browser.

You may need to install w3m with sudo apt-get install w3m if you do not have it already.

  1. create a new directory. mkdir /tmp/testing
  2. CD into new dir cd /tmp/testing
  3. Start http-server with `http-server . -a localhost -p 1234
  4. Visit http://localhost:1234 with w3m w3m http://localhost:1234/
  5. Start http-server with `http-server . -a localhost -p 80
  6. Visit http://localhost in a w3m w3m http://localhost/ does it work?
Kinetic
  • 1,531
  • 12
  • 33
  • `netstat -lntu | grep :80` After trying this, I got: `tcp 0 0 myipaddress 0.0.0.0:* LISTEN` I tried ```sudo http-server -a [my ip address] -p 80 -c-1``` and just like the ```npm start```, it says the connection is available. However, when i go to that address using my browser, it says ERR_CONNECTION_REFUSED. Finally, removing sudo from the json package gives me an EACCESS error in the console. – rohan Mar 11 '16 at 14:27
  • Something is already running on port 80, you will need to close it. Probably another web server such as apache. Try sudo /etc/init.d/apache2 stop and then try runn9ing you app again. – Kinetic Mar 11 '16 at 14:29
  • Sorry, the only thing that was running on port 80 was my app. – rohan Mar 11 '16 at 14:31
  • Are you using socket.io? – Kinetic Mar 11 '16 at 14:32
  • No, I am not using socket.io – rohan Mar 11 '16 at 14:44
  • Ok back to basics... I've added another possibility to my answer we need to make sure http-server is working on your setup – Kinetic Mar 11 '16 at 15:01
  • Yep, seems like it works. So http-server works fine. And my app works in w3m as well so I have reason to believe it is a problem with my browser/local machine – rohan Mar 11 '16 at 15:18
  • OK the problem is probably a firewall blocking port 80 between you and your server, and not actually http-server or nodejs. Unfortunately there isn't much more advice i can give you - without knowing the specifics of your system. Checking IPTables would be a good place to start on the server, the other possibility is that its your local machine which could be at fault which again is outside of the scope of a stack overflow answer. – Kinetic Mar 11 '16 at 15:19
  • So I nuked my firewall using iptables, and it works! Not secure at all, but it works. – rohan Mar 11 '16 at 16:06
0

Quick tests:

Try to access this on as the localhost address, either localhost or 127.0.0.1 to shortcut any potential firewalls.

Try to telnet to this address on port 80 to see what the server replies (if any).

0

Do you have Apache installed? Are sure putting your application server on port 80 is not in conflict with Apache?

In that case it is better to redirect port 80 to your application server that just starting it on the Apache port.

White Feather
  • 2,439
  • 1
  • 12
  • 21
0

Is it error 102? Check this link. Probably it's caused by some extensions you installed.

hankchiutw
  • 1,140
  • 8
  • 15
-1

To run nodejs apps with pot less than 1000 you need a root access. Use sudo node app.js Also dont forget to open firewall. And make sure nobody else listening on port 80.

Sergey Yarotskiy
  • 3,404
  • 2
  • 16
  • 27