preloader

Domain Redirection To Tomcat Via Apache2 in Ubuntu

slide12_01

First, make sure mod_proxy is enabled by running:

-> sudo a2enmod proxy
-> sudo a2enmod proxy_http
-> service apache2 restart

Then create a new virtual host in a file named /etc/apache2/sites-available/yourdomain.conf . Follow the below steps to configure it to point your domain to your Tomcat app

Step 1 : Copy 000-default.conf file (Location: /etc/apache2/sites-available)
Step 2 : Rename file to yourdomain.conf (Example: example.com.conf)
Step 3 : Add the below lines in <VirtualHost *:80>—– Below Lines —-</VirtualHost>

    # ------------Lines Start -----------------  
      ServerName yourdomainname.com
      ServerAlias www.yourdomainname.com
      ProxyRequests On
      ProxyPass / http://localhost:portnumber/applicationname/
      ProxyPassReverse / http://localhost:portnumber/applicationname/
      ProxyPassReverseCookiePath /applicationname /
    # -------------- Lines End -----------------------
    # The last line is for maintaining the cookies. 

Finally, enable the site and reload Apache:

sudo a2ensite yourdomain.conf
sudo service apache2 reload

1 Comment

  • Danial April 25, 2021

    Thanks, this article helped me a lot

Leave a Reply

Your email address will not be published. Required fields are marked *