41

What is the difference between localhost/web vs. localhost:8080/web?

Prakash K
  • 11,669
  • 6
  • 51
  • 109
whamsicore
  • 8,320
  • 9
  • 40
  • 50
  • 6
    If you do not specify a port in a URL then the user agent will assume a default. The default is normally 80 for http and 443 for https URLs. – eckes Nov 12 '17 at 06:27

6 Answers6

52

A TCP/IP connection is always made to an IP address (you can think of an IP-address as the address of a certain computer, even if that is not always the case) and a specific (logical, not physical) port on that address.

Usually one port is coupled to a specific process or "service" on the target computer. Some port numbers are standardized, like 80 for http, 25 for smtp and so on. Because of that standardization you usually don't need to put port numbers into your web adresses.

So if you say something like http://www.stackoverflow.com, the part "stackoverflow.com" resolves to an IP address (in my case 64.34.119.12) and because my browser knows the standard it tries to connect to port 80 on that address. Thus this is the same as http://www.stackoverflow.com:80.

But there is nothing that stops a process to listen for http requests on another port, like 12434, 4711 or 8080. Usually (as in your case) this is used for debugging purposes to not intermingle with another process (like IIS) already listening to port 80 on the same machine.

Note from 2021: When I made this post, I used port 80 as example because even though the OP didn't specify a protocol, http was the usual web request standard back then and 80 ist the standard for http. Nowadays pretty much everything runs on https and the standard port for that is 443.

TToni
  • 9,145
  • 1
  • 28
  • 42
  • 6
    I see. So 8080 is mostly a debugging/testing convention... How will using port 80 interfere with another process though? Isn't port 80 being accessed simultaneously all the time? Thanks. – whamsicore Jan 27 '11 at 23:50
  • 6
    Port 80 can be accessed my multiple clients, but there can be only one process that "takes the calls" and handles them. I'm not 100% sure, but I believe you will get an error if you try to listen to a port that some other process already has open in listen mode. – TToni Jan 28 '11 at 07:56
  • 8
    You definitely will. The call to `bind()` will fail, with similar sematics across platforms. Note that you can listen on the same port on different interfaces though (e.g. if your interfaces have IP addresses 192.168.1.123 and 127.0.0.1, you could have different processes listen at 192.168.1.123:80 and 127.0.0.1:80 without a problem). – Piskvor left the building Jan 28 '11 at 13:48
  • Note that on Windows systems you can listen to http requests on a single port/ip with multiple processes - sort of. This is because of a kernel driver named `http.sys` which allows you to register URLs for a process and distributes the requests accordingly. So from the TCP/IP stack point of view you still have a single receiver, but it's the Windows kernel now. See https://www.codeproject.com/Articles/437733/Demystify-http-sys-with-HttpSysManager for more details. – TToni May 28 '18 at 17:08
17

localhost/web is equal to localhost:80/web OR to 127.0.0.1:80/web

localhost:8080/web is equal to localhost:8080/web OR to 127.0.0.1:8080/web

desertnaut
  • 57,590
  • 26
  • 140
  • 166
nrph
  • 335
  • 7
  • 18
  • 2
    My home is 127.1.2.3, ha! In fact everything that starts with "127." resolves to the local host. – TToni Jan 27 '11 at 23:30
4

the localhost:8080 means your explicitly targeting port 8080.

Greg Buehler
  • 3,897
  • 3
  • 32
  • 39
2

http uses port 80, and understandably, your internet browser will automatically use that port when you type in an address - unless you specify another port. Now, when running a web server on your computer, you need to access that server somehow - and since port 80 is already busy, you need to use a different port to successfully connect to it. Although any open port is fair game, usually such a server is configured to use port 8080, hence when accessing your server you type in:

http:// (protocol) localhost (your computer) :8080 (port 8080) / (path pointing to the root of the public folder of your server)

Siddhartha
  • 492
  • 1
  • 5
  • 15
2

http: //localhost:8080/web

Where

  • localhost ( hostname ) is the machine name or IP address of the host server e.g Glassfish, Tomcat.
  • 8080 ( port ) is the address of the port on which the host server is listening for requests.

http ://localhost/web

Where

  • localhost ( hostname ) is the machine name or IP address of the host server e.g Glassfish, Tomcat.
  • host server listening to default port 80.
atiqkhaled
  • 386
  • 4
  • 19
2

http://localhost:8080/web: localhost ( hostname ) is the machine name or IP address of the host server e.g Glassfish, Tomcat. 8080 ( port ) is the address of the port on which the host server is listening for requests.

http://localhost/web: localhost ( hostname ) is the machine name or IP address of the host server e.g Glassfish, Tomcat. host server listening to default port 80.

Makyen
  • 31,849
  • 12
  • 86
  • 121