Tomcat Integration Apache

Source: Internet
Author: User

It lasted 4 hours and finally 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.


The difference between Apache and Tomcat in the background 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 is to improve the access speed of the whole system.
We put Apache and Tomcat together, and all of our requests are given to Apache first, if the specific request is HTML (also including static resources such as. jpg,.js) directly to Apache, if 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 of MOD_JK must match the version of Apache
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've been stressing the issue of versioning because the versions of the various components I downloaded myself did not match, wasting a lot of time in the middle.

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 of the article you're reading so that at least there's no version conflict.

Beginners, once encountered this version of the problem, is very anti-active.


Integrated MOD_JK

Unzip the 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 directory.

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

At the end of the httpd.conf add

 # Set up the virtual host, define the port as Bayi <virtualhost 127.0.0.1:81> ServerName 127.0.0.1 #定义服务名称 e:/a Pache-tomcat-6.0.44-8500/webapps is the location of my tomcat DocumentRoot "E:/apache-tomcat-6.0.44-8500/webapps" #定义站点项目所在路径, referring to the path To the default Web site directory in Tomcat directoryindex index.html index.htm index.jsp errorlog logs/shsc-error_log.txt # #下面例子中的aj P13, please remember, we will also use Customlog logs/shsc-access_log.txt common #例子1, let Apache support the Webapps/sun.shop/blog in the page transfer Jkmou nt/sun.shop/blog/* ajp13 #例子2, when requesting this folder page from Apache, the system will turn to use Tomcat to parse Jkmount/*.jsp ajp13 #例子4, when requesting a JSP page from Apache , use Tomcat to parse Jkmount/*.do ajp13 #例子5, request to Apache. Do action, use Tomcat to parse Jkmount/*.action ajp13 #例子6, to A Pache request. Action action, parse with Tomcat </VirtualHost> # allow clients to access this path <directory "E:/apache-tomcat-6.0.44-8500/webapp S "> Options Indexes followsymlinks allowoverride None Order allow,deny allow from all </di Rectory> 

To tell the truth, I don't know what's the difference between the directory behind directory and the directory in the DocumentRoot in VirtualHost.

At the moment, I've set this two path all the way, and it's 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 directory.
http://localhost:81/PathTest/
Enter the above address in the browser.

Change an address

If your browser can appear similar to the above, it 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 changes can be.

Set Tomcat

Set how Tomcat would accept Apache's request.

In the previous step we had this configuration
Jkworkersfile "E:/apache-tomcat-6.0.44-8500/conf/workers.properties"
In so go to Tomcat's Conf directory to see, and did not workers this file, how to do? Just make a new one. and write the following content:


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 modify if not occupied worker.ajp13.host= LocalHost #本机, if the above Apache host is not localhost, make the corresponding modification worker.ajp13.type=ajp13 #类型worker. ajp13.lbfactor=1 #代理数 without modification


Everybody, look at this line.
WORKER.LIST=AJP13 #模块版本
The ajp13 of jkmount/sun.shop/blog/* ajp13 in the ajp13 and httpd.conf are corresponding
It is also possible for you to change the 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, let's give it a try.
Turn on Tomcat and access http://localhost:8500/PathTest/jsp/a.jsp
is a very simple 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.
Then visit http://localhost:81/PathTest/jsp/a.jsp
Note that our port number is 81 and is accessed by 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.
If http://localhost:81/PathTest/jsp/a.jsp and http://localhost:8500/PathTest/jsp/a.jsp return the same result.
This means that Apache and Tomcat are integrated.




Possible issue 1 When you start Apache, this error pops up the requested operation has failed
If it is not a port problem, then it is Httpd.conf was modified by us wrong.
What to do
In the command line, enter the installation directory Apache\bin, use the command httpd-t, and then appear "Syntax Error on lines 133 of E:/apache\conf/httpd.conf:serveradmin takes one Argum ENT, the email address of the the server administrator ", see it tip information, description, in this configuration file inside the 133 lines, there is a problem
As for that line of specific what is the problem, we can then Baidu.
2 above the configuration, we are in the 81 port, access to html,jsp,js,jpg is no problem, in-depth even after joining the MVC framework. Do,.action can be handled normally.
But what if we're visiting a servlet?
There is no particularly good method at the moment.
Add this to the VirtualHost under httpd.conf.
Jkmount/*/servlet/* ajp13
What does that mean?

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


This article refers to a lot of blogs, the specific reference information will not be listed

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.