Redirect Apache Request to Tomcat

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:

#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

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.

<connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

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.

	ProxyPass         /  ajp://localhost:8009/
	ProxyPassReverse  /  ajp://localhost:8009/

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.


	ProxyPass         /app1  ajp://localhost:8009/app1
	ProxyPassReverse  /app1  ajp://localhost:8009/app1
 
	ProxyPass         /app2  ajp://localhost:8009/app2
	ProxyPassReverse  /app2  ajp://localhost:8009/app2
 
	ProxyPass         /app3  ajp://localhost:8009/app3
	ProxyPassReverse  /app3  ajp://localhost:8009/app3

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. 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值