Tomcat Integration Apache

Source: Internet
Author: User

It lasted 4 hours and eventually integrated Tomcat with Apache.

In the middle of a variety of problems, is now recorded, but also hope to be a little help to the later.


Background Apache and Tomcat differences in connection you know:
Tomcat can process JSP pages and also handle HTML pages
Apache can only handle static resources, such as HTML pages, pictures, JS, and so on, and Apache handles HTML pages faster than Tomcat handles HTML.


That's to improve the overall system access speed.
We put Apache and Tomcat together, and all of our requests were first given to Apache, assuming that the detailed request was HTML (and static resources such as. jpg,.js) to be processed directly by Apache, assuming it is a JSP or servlet dynamic information, is given to Tomcat for processing.


Download and install JDK 1.7
Tomcat 6 (Tomcat7 seems to have some problems in the integration, everyone use TOMCAT6 bar)
Apache 2.2.4
Mod_jk This is what is sent to Tomcat for a dynamic request that Apache cannot handle. It is important to note that the version number of the MOD_JK must match the Apache version number
I suggest you directly on Baidu search "mod_jk-1.2.26-httpd-2.2.4" or to http://download.csdn.net/download/wng1978/6708623 here directly download
I have always stressed the issue of version numbers, because I downloaded the various components of the version number mismatch, the middle of wasting a lot of time.

So, let me say a second digression.

When you're new to something, especially when you're in a staging environment, it's best to download the components according to the version number that you read in the article, so at least there's no issue with version number collisions.

people who have just started to learn, once encountered this issue of the version number, is very aggressive.




Integrated MOD_JK

Unzip Mod_jk-1.2.26-httpd-2.2.4.rar, get mod_jk-1.2.26-httpd-2.2.4.so, rename it to mod_jk.so and place it in modules under Apache's installation folder.

Edit apache/conf/httpd.conf File Find Listen 80 this line (CTRL+F) changed to Listen 81

At the end of the httpd.conf add

 # Set up virtual host, define port for Bayi <virtualhost 127.0.0.1:81> ServerName 127.0.0.1 #定义服务名称 e:/apache-tomcat-6.0.44-8500/web Apps is the location of my tomcat DocumentRoot "E:/apache-tomcat-6.0.44-8500/webapps" #定义站点项目所在路径, point the path to the default site folder in Tomcat Direc Toryindex index.html index.htm index.jsp errorlog logs/shsc-error_log.txt # #以下样例中的ajp13, please remember, we'll use Custo in the back.     Mlog Logs/shsc-access_log.txt Common #样例1, let Apache support page transfer to Webapps/sun.shop/blog jkmount/sun.shop/blog/* ajp13 #样例2, when a page is requested in this folder to Apache. The system will turn to use Tomcat to parse the Jkmount/*.jsp ajp13 #样例4. When requesting a JSP page from Apache, use Tomcat to parse the Jkmount/*.do ajp13 #样例5 and request the. Do action. Use Tomcat to parse the Jkmount/*.action ajp13 #样例6, request to Apache for the. Action action, parse with Tomcat </VirtualHost> # consent Client Visit this path <directory "E:/apache-tomcat-6.0.44-8500/webapps" > Options Indexes followsymlinks allowoverride N   One Order Allow,deny allow from all </Directory>

To be honest, I don't know what's the difference between the folder behind the directory and the folder in the DocumentRoot in VirtualHost.

Right now, I'm setting up this two path, all the way, WebApps under Tomcat.


After this step, we'll check if Apache is installed.


Check that I have deployed a project called Pathtest under E:/apache-tomcat-6.0.44-8500/webapps, and there is a index.html file under the root folder.
http://localhost:81/PathTest/
Enter the above address in the browser.



Change an address

Let's say that your browser can appear similar to the above, which means that Apache itself is already installed.


Connect Tomcat to connect Apache to Tomcat

And then add the following to Httpd.conf's back.


LoadModule Jk_module modules/mod_jk.so # here mod_jk.so file for your downloaded file jkworkersfile "e:/apache-tomcat-6.0.44-8500/conf/ Workers.properties "# Specifies the Tomcat listener profile address Jklogfile" E:/apache-tomcat-6.0.44-8500/logs/mod_jk2.log "# Specify the log storage location Jkloglevel Info

The above Tomcat address everyone according to their own modifications can be.

Set Tomcat

Set how Tomcat would accept Apache's request.

We have this configuration in the previous step.
Jkworkersfile "E:/apache-tomcat-6.0.44-8500/conf/workers.properties"
In so go to Tomcat's Conf folder to see, and did not workers this file, how to do? A new one will do. and write such as the following:


workers.tomcat_home=e:\apache-tomcat-6.0.44-8500 #让mod_jk模块知道Tomcat的位置workers. Java_home=c:\program files\java\ Jre7 #让mod_jk模块知道jre的位置ps =worker.list=ajp13 #模块版本号worker. ajp13.port=8009 #工作端口, do not change if not occupied worker.ajp13.host= LocalHost #本机, if the above Apache host is not localhost, make the corresponding changes worker.ajp13.type=ajp13 #类型worker. ajp13.lbfactor=1 #代理数, no changes.


Everybody, look at this line.
WORKER.LIST=AJP13 #模块版本号
The ajp13 of jkmount/sun.shop/blog/* ajp13 in the ajp13 and httpd.conf are correspondingly
It is also possible for you to change two ajp13 to "Mytomcat".


And worker.ajp13.port=8009 This port refers to the port of the AJP protocol in Tomcat, not the one we used to support HTTP 8080.


In other words this 8009, it is best not to change.


In addition, my Tomcat's port number was changed to 8500.
Where do you change it?




Under the Tomcat/conf/server.xml

    <connector port= "8500" protocol= "http/1.1"                connectiontimeout= "20000"                redirectport= "8443"/>       <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>

8500 and 8009 support two protocols respectively.




OK, now let's have a try.
Open Tomcat, Interview http://localhost:8500/PathTest/jsp/a.jsp
is a very easy JSP
Open Apache,
By the way, it hasn't been said how to start the Apache service.


There is a apachemonitor under the Apache/bin.

Double click



When the service is selected, start is available.
And then interview http://localhost:81/PathTest/jsp/a.jsp.
Note that our port number is 81 and is an interview with Apache.
Apache sees the requested address is JSP, through Jkworkersfile find Apache behind the Tomcat,tomcat processing, then the results to Apache, and then Apache to the browser.
Suppose http://localhost:81/PathTest/jsp/a.jsp and http://localhost:8500/PathTest/jsp/a.jsp return the same results.
This means that Apache and Tomcat are integrated.






Possible issue 1 When you start Apache, this error pops up the requested operation has failed
Assuming it's not the port problem, then httpd.conf was changed by us wrong.


What to do

In the command line, go to the installation folder Apache\bin. Use the command httpd-t. Then appears "Syntax Error on line 133 of E:/apache\conf/httpd.conf:serveradmin takes one argument, the email address of the serve R Administrator ", look at it tip information, description, in this configuration file in the face of 133 lines, there is a problem

What does the above 133-line error mean?

Add an address to the back, OK.

2 above the configuration, we are in 81port, access to ask html,jsp,js,jpg is no problem, in-depth and even add the MVC framework after the. Do,.action can be handled normally.
But what we're supposed to be visiting is the servlet?
There is no particularly good way at the moment.


Add this to the VirtualHost under httpd.conf.
Jkmount/*/servlet/* ajp13
What does that mean?


If the requested URL includes the character "servlet" in the middle, Apache sends it to Tomcat.


This article has participated in a lot of blog, detailed reference information is not listed

Tomcat Integration Apache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.