It 's written in front .
There are already a lot of articles on how to integrate Apache2 with Tomcat (there are good writing), but sometimes there are some gaps in practice, the so-called practice of truth. To really do it, is to really understand.
The following is the practice of yesterday, in order to sum up, after less detours.
Software and version
Ubuntu 12.04 (64-bit)
Apache 2.2.22
Tomcat 7.0.55
AJP13 mod_jk-1.2.31-httpd-2.2.x
Configured on only one machine, only one tomcat (if there are two or more tomcat, you need to modify workers.properties).
Consolidation Steps
1. Installation of Apache2 and OpenJDK
These two installations require only the following commands to be executed
Apt-get Install Apache2
Is it correct to test the browser input http://ip_address after installation
Apt-get Install Openjdk-7-jre-headless
Perform java-version command after installation to test that the JDK installation is correct
2. Install Tomcat 7
Download http://tomcat.apache.org/download-70.cgi to the Tomcat 7 download page. Using the wget download in the Ubuntu system, the commands are as follows
wget http://apache.fayea.com/apache-mirror/tomcat/tomcat-7/v7.0.53/bin/apache-tomcat-7.0.53.tar.gz
After downloading use the tar command to decompress. and run the test under.
The default 8080 port and AJP13 8009 ports are used here.
3. Install AJP13 and configure
AJP13 is a connector that connects Apache2 with Tomcat. Implemented by MOD_JK, commands are as follows
Apt-get Install LIBAPACHE2-MOD-JK
After installation to the/ETC/LIBAPACHE2-MOD-JK directory, see if there is no workers.properties
Use the vi workers.properties command to edit the file.
You need to modify the following several places
1. Modify the Workers.tomcat_home and Workers.java_home values to the correct path (this step is optional, but the recommended configuration)
2. Add the Jk-status,jk-manager value after Worker.list and configure the following
Worker.list=ajp13_worker,jk-status,jk-manager
(If you do not add these two values to see some warning message after Apache2 starts)
Jk-status and Jk-manager are used to monitor the operation and management of MOD_JK (the default can only be accessed on this computer)
Others use default values, where you can see that a worker named Ajp13_worker has been created by default. Remember this name, later for use.
Remember to save after modification.
4. Configure blocking Rules
The most important point here is to specify which URLs are handled by Apache and which URLs need to be transferred to Tomcat processing. (The recommended rule is: all static resources are handled by Apache, such as pictures, Js,css, dynamically transferred to Tomcat, such as loading data, business processing parts)
Enter the/etc/apache2/sites-available directory. Edit Default file (Command VI default)
Add before </VirtualHost> tag with the last </Directory>, for example, below
Jkunmount/*.js ajp13_worker
jkunmount/*.css ajp13_worker jkunmount/*.htm ajp13_worker JkUnMount/*.png
Ajp13_worker
jkunmount/*.gif ajp13_worker
jkunmount/*.jpg ajp13_worker jkunmount/*.jpeg ajp13_worker
Jkmount/*.jsp Ajp13_worker
Jkmount/*.ZSFZ Ajp13_worker
You should see it. jkunmount specifies which matching URLs are handled by Apache, Jkmount specifies which matching URLs are transferred to Tomcat, and configures all URLs that end with zsfz,jsp to Tomcat processing. Remember the ajp13_worker that you remember before.
In addition to using Jkunmount and Jkmount methods, there are other ways. Here is the reader to expand the study under it.
Last modified, don't forget to save it.
At this point, the integration configuration is complete, down is tested.
1. In Tomcat's WebApps directory, first delete all previous files (and folders), create a new root directory, a test.jsp file in the root directory, and add some content.
Start Tomcat through the http://ip_address:8080/test.jsp access test.jsp to ensure the test passes (note here is direct access to Tomcat)
2. Restart Apache2, command/etc/init.d/apache2 restart
With http://ip_address/test.jsp access, if access is successful and the content is consistent with previous direct access to Tomcat, the configuration is successful (note: no port here)
Similarly, you can put a picture into the root directory of Apache2/var/www, and direct access to see if it succeeds.
Finish
---------------------------------------------------------------------
Useful Extensions
Support for Chinese in the URL. (if the test in Chinese URL parameters will appear garbled, this is the problem of character encoding), by setting UTF-8 code to solve
1. Set the Apache default character encoding to UTF-8. After the installation is completed enter the/etc/apache2/conf.d/directory, edit the charset file, the inside of the Adddefaultcharset UTF-8 front of the # number to cancel and save, remember to reboot.
2. Edit Tomcat's Conf/server.xml file to add uriencoding= "UTF-8" content to the AJP13 configuration inside. After adding the following
<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443" uriencoding= "UTF-8"/>
OK, support the Chinese parameter.
Reference articles
http://yr512656630.iteye.com/blog/933458
Http://www.cnblogs.com/junsong/archive/2012/07/03/2574447.html