Rajarshee Mitra
Rajarshee Mitra

Reputation: 1905

access tomcat application via the domain name

I have a virtual cloud server on aws where there is tomcat 7 running on port 8080 eg. a.x.y.z:8080 (where a.x.y.z is the public ip). I have an application deployed on the tomcat on context path "hello" so that I can access it like a.x.y.z:8080/hello . Now I have bought a domain name example.com and have translated it to the public ip a.x.y.z so that now I can access my application via the url example.com:8080/hello but actually what I want is that on hitting example.com I would be able to access my application. How to achieve it ?

Upvotes: 0

Views: 3421

Answers (2)

Rajarshee Mitra
Rajarshee Mitra

Reputation: 1905

Ok, I solved the issue :

After installing apache2, in the /etc/apache2/apache2.conf file I appended :

<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName www.example.com
  ServerAlias example.com
  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://localhost:8080/
</VirtualHost>

Saved the file and restarted the apache2 server. With this, whenever I hit example.com, I will get the homepage of tomcat (localhost:8080). then i opened the tomcat manager (example.com/manager/html) and stopped & undeployed the application at root (/) path. (As a result of this, whenever you hit example.com, you will no longer see tomcat homepage, instead a blank page)

Now I deployed my application as root in tomcat. If you are using maven you can do so like here . As a result of this my application was available in example.com . (If you don't deploy your application as root, you have to access it using example.com/myapp)

Now, whenever I hit example.com myapp will be accessed.

Upvotes: 0

24x7servermanagement
24x7servermanagement

Reputation: 2540

You can access your tomcat application with your domain name using mod_proxy modules, please login your server and update your httpd configuration with following code.

ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/

NOTE : Update your correct server IP instead of 0.0.0.0 in above code.

Upvotes: 0

Related Questions