简体   繁体   中英

How to access the local web application with domain name instead of localhost/IP address?

I have a Java based webapplication hosted on a local Tomcat server. As of now, I am accessing it with a URL like http://localhost:8080/myApp . But I want to access it with a domain name, something like http://us.localApp.com/myApp . Simlilary I want other's machines, which are on the network, to access it by this domain URL only. Do I have to make the changes in my application or Tomcat settings for this or do I need to mention just an entry like 127.0.0.1 us.localApp.com in my hosts file .

I can see this entry in appConfig.xml and also saw some people accessing with localApp.com <!ENTITY appDomain "localApp.com"> , but how should I go about it?

I have made the entry 127.0.0.1 google.com in the hosts file. When I type http://google.com I expect it redirect to the local application, that is, my application, but still it is going to the Google site. Why?

The hosts file is the easiest way I can think of, but it will need to be implemented locally on each machine. The alternative would be to install a local DNS server on your network and route that specific DNS request to your application server.

  1. Host file do not accept wildcards (some apps like angryhosts do). Your address must include subdomain, at least the default one: www.localApp.com

    Host file doesn't know about ports. You have to access your app like us.myApp.com:8080/myApp or change your tomcat port to web default (80). If you need a separate logic for this subdomain, use an interceptor class.

    This approach would be only for testing purposes since you have to do it in each computer accessing your app.

  2. Use Tomcat Virtual Hosting http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

If you want to access your app as www.myApp.com instead of www.myApp.com/myApp, you might want to delete your ROOT project folder in Tomcat and rename your app to ROOT. Or read the comments of this post: http://benhutchison.wordpress.com/2008/07/30/how-to-configure-tomcat-root-context/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM