"localhost:8080" works fine but "localhost" doesn't

2

"localhost:8080" works fine but is it mandatory to give the port number always, because it doesn't work when I just type "localhost"

Nick Div

Posted 2014-03-11T19:35:00.193

Reputation: 137

If you're serving stuff only on 8080 and nothing on 80, and you don't have redirects or anything, then yes, it will only work with 8080 at the end of it. – shinjijai – 2014-03-11T19:37:45.623

What doesn't work? are you talking about apache2 web service? as in you can't reach the page if you don't specify port 8080? localhost is just an address (127.0.0.1), so if apache is listening only on 8080, and localhost in a browser will assume 80 at best, then you're not going to see anything but whatever is listening on port 80, which is nothing. – MaQleod – 2014-03-11T19:38:59.153

My apache is deployed on port 8080, and I am going to use only that port.. But by default when we enter "localhost" in the address bar I want it to open whatever opens by specifying the port localhost:8080. So basically I want "localhost" to behave like "localhost:8080" I think by default it goes to port 80 – Nick Div – 2014-03-11T19:42:16.870

Are others going to connect to you through NAT? or are they connecting on the LAN? – MaQleod – 2014-03-11T19:48:20.170

Answers

5

The IANA has assigned 80 as the HTTP well-known port number.

So browsers use this port by default.

If something is listening on a different port, you have to specify the port.

If you want your localhost-listening webserver to accept requests on port 80, you need to configure it to do that.

LawrenceC

Posted 2014-03-11T19:35:00.193

Reputation: 63 487

I dont want to change the port number in Apache is it possible to make the HTTP go to 8080 by default – Nick Div – 2014-03-11T19:43:52.617

Some browsers may let you configure (Firefox probably has something hidden in about:config to do it, but possibly not) and you can set up a local proxy server to force it, but then you're going to have to specify http://yahoo.com:80 for example when you want to access every other site. Edit: I guess you could have a simple TCP proxy or tunnel listening on localhost:80 forwarding to localhost:8080, though if you wanted. Maybe something like this: http://www.vakuumverpackt.de/tcptunnel/

– LawrenceC – 2014-03-11T19:45:39.760

@ultrsawblade: Ok I will give TCP tunnel a try. Thanks a lot – Nick Div – 2014-03-11T19:49:22.883

0

if you want localhost to behave like localhost:8080 you have to configure apache to open the both ports. here is how:

  1. Open apache configuration file. (httpd.conf you knew that.)
  2. Search for the word Listen and you will see something like this:
Listen 127.0.0.1:8080
  1. Add this line after it and save it. then restart apache.
Listen 127.0.0.1:80

TechLife

Posted 2014-03-11T19:35:00.193

Reputation: 822