If we want to access website by domain name without entering any port no than we can access that website by port 80 but unlike PHP which runs on HTTP Web Server; Java based websites run on 8080 which is default port for Apache Tomcat. In this article we will learn on how we can redirect Apache request to Apache Tomcat.
Software Requirement:
Apache Web Server(httpd) 2.2+
Apache Tomcat 5.5+
Configuring Apache Web Server
I am assuming that you have already installed Apache Web Server and Apache Tomcat in the system. Now open httpd.conf located inside [Apache Web Server Folder]/conf/httpd.conf. Check for mod_proxy.so and mod_proxy_ajp.so. The line that you are looking at will look something like:
Uncomment the above line by removing the hash from start.
AJP Port Configuration in Apache Tomcat
Now we will be checking the AJP port used inside Apache Tomcat, we can find this inside [Apache Tomcat Folder]/conf/server.xml. Check for following lines.
The port no may change if you have changed any configuration otherwise you can search for “AJP” word. If you found the above line you will notice that the AJP port in use is 8009. Now we would be using this port no inside httpd.conf, for redirecting port 80 request to port 8009.
Redirect Apache Request to Apache Tomcat
After uncommenting the mod proxy module, now it’s time to add the entry for redirection and for this go to bottom of httpd.conf file and add following lines.
The above statement says that redirect all request from port 80 to Tomcat ROOT folder(Assuming you have deployed your website inside ROOT folder). But if you want to redirect request to multiple application than will have to modify the above code to add the application name.
Here if you see if i set the ProxyPass for three applications app1, app2 and app3. In simple words it says that redirect all request that has /app1 in URL to app1 application deployed in Apache Tomcat.