So you have a VPS and want to host both a Tomcat application and an Apache application on it. Sure, you can run them on different ports—but if you want your JSP app to also run on port 80, you can use Apache’s mod_proxy to make that happen. Follow the steps below to run your JSP application with Apache using mod_proxy.
First, edit your Apache configuration file for your website:
$ sudo vim /etc/apache2/sites-available/servername.com.confAdd or edit the file and include the following configuration below your ServerName:
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / <a href="http://servername.com:8080/">http://servername.com:8080/</a>
ProxyPassReverse / <a href="http://servername.com:8080/">http://servername.com:8080/</a>Now your configuration should look something like this:
<VirtualHost *:80>
SuexecUserGroup apache apache
ServerName servername.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / <a href="http://servername.com:8080/">http://servername.com:8080/</a>
ProxyPassReverse / <a href="http://servername.com:8080/">http://servername.com:8080/</a>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</VirtualHost>Quit the editor and restart Apache:
$ sudo service apache2 restartNote: Use SuexecUserGroup www-data:www-data for Ubuntu, and SuexecUserGroup apache:apache for CentOS. You can also check which user is being used in your apache config
Now your Tomcat (JSP) application should be accessible on port 80. This setup will also work with other backends such as Python (Django) or Node.js. If there are any questions or feedback, feel free to leave a comment.
