Introduction
This article provides the procedure to configure a proxy from Apache to Tomcat.
Procedure
- Log into the server as the 'root' user via SSH or "Terminal" in WHM.
- Determine the AJP port from the Tomcat configuration in /home/username/ea-tomcat85/conf/server.xml.
[root@server ~]cPs# grep 'Connector port.*AJP' /home/username/ea-tomcat85/conf/server.xml
This example shows that the AJP port for this domain is 10005.
<Connector port="10005" protocol="AJP/1.3" xpoweredBy="false" secretRequired="false"/>
[root@server ~]cPs# - Create the Apache include folders for the domain.
mkdir -p /etc/apache2/conf.d/userdata/std/2_4/username/domain.tld
mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/username/domain.tld - Edit /etc/apache2/conf.d/userdata/std/2_4/username/domain.tld/tomcatproxypass.conf with a text editor, such as nano or vim.
- Add the following to /etc/apache2/conf.d/userdata/std/2_4/username/domain.tld/tomcatproxypass.conf. Be sure to replace "portnumber" with the port number found above.
<IfModule proxy_ajp_module>
ProxyPass "/" "ajp://127.0.0.1:portnumber/"
</IfModule> - Save the changes and exit the text editor.
- Edit /etc/apache2/conf.d/userdata/ssl/2_4/username/domain.tld/tomcatproxypass.conf with a text editor, such as nano or vim. Be sure to replace "portnumber" with the port number found above.
<IfModule proxy_ajp_module>
ProxyPass "/" "ajp://127.0.0.1:portnumber/"
</IfModule> - Save the changes and exit the text editor.
- Restart Apache.
/scripts/restartsrv_httpd
Please note that if you are loading a website from the domain's document root, you may need to use another path for the ProxyPass statement other than /. For instance, if you want your Tomcat application to load from /javaapp, you will add the following statement to the Apache include. Be sure to replace "portnumber" with the port number found above.
<IfModule proxy_ajp_module>
ProxyPass "/javaapp" "ajp://127.0.0.1:portnumber/"
</IfModule>