Sometimes you need to connect Tomcat server to an Apache front and a good solution can be to use mod_poxy. Modproxy is the Apache module for redirecting connections, mod_proxy_ajp is used for working with the AJP13 protocol (Apache JServ Protocol version 1.3). The idea to pass the requests to Tomcat via the AJP protocol.
If you haven't changed the default server settings for Tomcat this should work just as it is. Otherwise make sure to specify the AJP port that is configured in Tomcat's conf/server.xml file. There should be a line similar to this:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
After <Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
Insert
<Host name="mywebsite.com" appBase="webapps" unpackWARs="false" deployXML="false" path="/mywebsite" >
<Alias>www.mywebsite.com</Alias>
<Context path="" reloadable="true" docBase="/usr/share/tomcat/webapps/mywebsite" debug="1"/>
</Host>
Create a virtual host for tomcat throught mod_proxy_ajp
Include a similar directive for each web application that you wish to forward to Tomcat 7. In CentOS7 create the file mywebsite.com.conf in /etc/httpd/conf.d
For example
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias www.mywebsite.com
ServerAdmin webmaster@mywebsite.com
UseCanonicalName Off
Options -ExecCGI -Includes
RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
CustomLog /etc/httpd/logs/mywebsite.com combined
CustomLog /etc/httpd/logs/mywebsite.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
The mod_proxy_ajp will forward you request transparently using the AJP protocol to the Tomcat application server.
0 comments:
Post a Comment