What exactly is going on when I go to localhost:8080 in my web browser? (Apache Tomcat)

What exactly is going on when I direct my web browser to go to localhost:8080?

  1. You are causing your web browser to ask your operating system to resolve the hostname localhost. Operating systems will normally resolve the hostname localhost to 127.0.0.1, your loop back interface.

  2. Any hostname or IP address followed by a : and a port number like :8080 tells the browser to connect to that TCP port instead of the default web-server port 80.

    Just as http://localhost:80/, http://localhost/, http://127.0.0.1/:80, and http://127.0.0.1/ each connect to the same server and port, so does http://localhost:8080/ and http://127.0.0.1:8080/ also connect to the same ip address but on TCP port 8080

Additional Note: In HTTP/1.1, even though the web browser connects to the same IP address and port, to many web-servers, there is a slight difference between localhost and 127.0.0.1. Depending what is in the address bar, your browser will send a request header field with either Host: localhost or Host: 127.0.0.1 in it. When a web server is properly configured, the browser's Host header field allows a single web-server to listen on a single IP address port and serve different webpages for many different domains that resolve to the same IP address.

How does the operating system typically resolve hostnames like localhost?

  1. On Unix systems or Unix like OS such as Linux or Freebsd, the file is /etc/hosts, and is likely to have lines like:

    127.0.0.1   localhost
    ::1     localhost ip6-localhost ip6-loopback
    
  2. On windows, the file is c:\windows\system32\drivers\etc\hosts and will usually have a similar line:

    127.0.0.1   localhost
    

Additional note: If you like, you can add lines to your hosts file like:

127.0.0.1     localhost
127.0.0.1     developer.yourdomain.com
# Deny Browser Request For These Sites
127.0.0.2     www.spam.advertisements.com
127.0.0.2     super.ads.com
# Block These Sites
127.0.0.3     www.dont.go.here.com
127.0.0.3     nsfw.stuff.com 
  • The Uniform resource locator (URL) http://developer.yourdomain.com:8080/ in your browser's address bar, directs the web browser to make a TCP connection to port 8080 of your local loopback address 127.0.0.1.

  • Furthermore, acording to rfc1700 page 4 any address in the 127.0.0.0/8 range is also a loopback address. Thus, a properly configured webserver running on your computer could deny all request on port 127.0.0.2 while giving a generic "You should not go here. The site is blocked" message for connections on 127.0.0.3.

Where is the tomcat page coming from?

Apache Tomcat is a server that listens on a port and runs java programs that generate content to send to your browser.