Ubuntu: Http-server on port 80 starting up, but can't access from browser?
Asked Answered
A

5

7

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?

Astrogeology answered 11/3, 2016 at 13:59 Comment(0)
F
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).

Foppery answered 11/3, 2016 at 14:7 Comment(6)
how do I telnet the address on port 80?Astrogeology
$telnet 127.0.0.1 80Chaucerian
or basically, run the command telnet (you dont need to be root to do this) with the first parameter being your address, and the second parameter being the port.Chaucerian
telnet: could not resolve 127.0.0.1:80/telnet: Name or service not knownAstrogeology
nvm I had the colon. without the colon, it connects successfullyAstrogeology
I would try what this site recommends, rootusers.com/how-to-test-network-connectivity-with-telnetChaucerian
E
5

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?
Epistemology answered 11/3, 2016 at 14:21 Comment(9)
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.Astrogeology
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.Epistemology
Sorry, the only thing that was running on port 80 was my app.Astrogeology
Are you using socket.io?Epistemology
No, I am not using socket.ioAstrogeology
Ok back to basics... I've added another possibility to my answer we need to make sure http-server is working on your setupEpistemology
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 machineAstrogeology
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.Epistemology
So I nuked my firewall using iptables, and it works! Not secure at all, but it works.Astrogeology
I
1

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.

Inconsistent answered 11/3, 2016 at 14:16 Comment(0)
F
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).

Foppery answered 11/3, 2016 at 14:7 Comment(6)
how do I telnet the address on port 80?Astrogeology
$telnet 127.0.0.1 80Chaucerian
or basically, run the command telnet (you dont need to be root to do this) with the first parameter being your address, and the second parameter being the port.Chaucerian
telnet: could not resolve 127.0.0.1:80/telnet: Name or service not knownAstrogeology
nvm I had the colon. without the colon, it connects successfullyAstrogeology
I would try what this site recommends, rootusers.com/how-to-test-network-connectivity-with-telnetChaucerian
S
0

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

Selenodont answered 11/3, 2016 at 15:55 Comment(0)
E
-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.

Emphasis answered 11/3, 2016 at 14:15 Comment(1)
I'm connected to port 80, no problem. I just cannot access it from a browser.Astrogeology

© 2022 - 2024 — McMap. All rights reserved.