apachetomcatdigital-oceanmod-proxydomain-mapping

CSS & images breaking after mapping application deployed on Tomcat to my domain


I've installed Tomcat 9.0.27 on my Digital Ocean droplet running Ubuntu 18.04.3. I deployed my Java WAR on Tomcat and am able to access it on the URL: http://example.com:8080/app_name
I want to be able to directly access my WAR serving JSP through my domain. So, when I hit example.com it directly serves my Java application.

I have tried several links to do the same. According to one of them (https://www.digitalocean.com/community/questions/how-to-tie-domain-name-with-application-running-on-tomcat), I did the following steps:
1. Enabled "proxy" and "proxy_http" using a2enmod
2. Restarted Apache2 service using systemctl restart
3. Created a new virtual host in a file named /etc/apache2/sites-available/tomcat.conf with the following contents:

<VirtualHost *:80>
    ServerName www.example.com

    ProxyRequests On
    ProxyPass / http://localhost:8080/app_name/
    ProxyPassReverse / http://localhost:8080/app_name/
</VirtualHost>
  1. Enabled 'tomcat' site using a2ensite
  2. Restarted Apache2 service using systemctl restart

Now when I hit example.com it does serve my homepage but all the CSS styles and images seem to be broken. The hyperlinks also don't work anymore. My application is still being served at example.com:8080/app_name and on this URL everything works perfectly.

Please help me out with this.


Solution

  • Fixed this by renaming my webapp to "ROOT" and copying it to Tomcat. Now the redirection is to http://localhost:8080.