Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 591
rohan Avatar asked Mar 11 '16 13:03

rohan


People also ask

How do I connect to HTTP port 80?

Select the protocol to use ( http:// or https:// ). Use the Server field to enter the name or IP address of the HTTP server. Do not include the scheme (i.e. http:// ) in this field. If your server is listening on a non-standard port (80 for http:// and 443 for https:// ) then enter the port number into the Port field.

Does HTTP have to run on port 80?

Our recommendation is that all servers meant for general web use should offer both HTTP on port 80 and HTTPS on port 443. They should also send redirects for all port 80 requests, and possibly an HSTS header (on port 443 requests).


1 Answers

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?
like image 102
Kinetic Avatar answered Sep 27 '22 21:09

Kinetic