Friday, 18 August 2017

Map localhost and port to a domain

In my previous post, I explained how to map localhost to a domain. In this post, I am going to explain, how to map localhost:port to a domain.

When user hit the URL in browser, browser establish connection with web server in the port 80 by default in case of HTTP, 443 by default in case of HTTPS.

By running the application server instance on port 80, we can access the application by domain name (we can exclude port number).

I am going to show you, how to run the application on localhost (excluding port number), followed by running the application using domain name.

Running application on localhost (Excluding port)
It is very simple, make sure your application server runs on port 80.

For example, by default tomcat runs on port 8080. In eclipse, you can see the configuration of tomcat by double clicking it.


Change the port number from 8080 to 80.

Run the application on server.
Map localhost to domain
By modifying local dns settings, we can point the localhost (or) 127.0.0.1 to some domain name.

We need to modify the hosts file.

Operating system
Host file location
UNIX
/etc/hosts
Windows
C:\Windows\System32\drivers\etc\hosts

I am going to show the demo in windows operating system, procedure is same for UNIX.

Now open hosts file and add below statement to it.

127.0.0.1 myexample.com

You can access the application using domain name. See the below screenshot.

You may like


No comments:

Post a Comment