您的位置:首页 > 运维架构 > Tomcat

Redirect Apache Request to Tomcat

2012-06-18 14:52 323 查看



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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐