bhargav desai
bhargav desai

Reputation: 119

Change localhost to something like localhost.dev in dynamic web project

I am creating a dynamic web project in java. I want to deploy it in a application server. By default we have hostname as localhost:port/appname. I want to change it to localhost.com/myapp. How can i do that? Do i need to change something in my project or tomcat or hostfile. Please elaborate.

Upvotes: 0

Views: 591

Answers (1)

Daniel Tung
Daniel Tung

Reputation: 427

I fear there may be some confusion about how web servers work.

In your browser the URL http://localhost:8080/application_name will resolve internally to 127.0.0.1 (localhost) as this is a built in address. 127.0.0.1 is a loop back address pointing to the machine you're on. If you're hosting the server on the same machine as the you're trying to navigate to this is why the localhost address works.

If you were on another machine you would need to either directly input the IP address of the server or use a DNS record to point the IP address to a URL you own and control.

Browser are also programmed to default to port 80 for http and port 443 for https so if you don't want to have to provide a port have your server bind to port 80. This way you'll only need to navigate to http://localhost/application_name

When deploying the application to a server you want to be externally accessible you'll purchase a domain, register the DNS record and point it at servers external IP address (You may need to configure firewall and network rules).

Upvotes: 2

Related Questions