This article is mainly about how to integrate apache2 and Tomcat under Ubuntu, assuming you have installed apache2 and Tomcat
Install MOD_JK First, this module is responsible for forwarding the request to Tomcat
sudo apt-get install LIBAPACHE2-MOD-JK
After installation, the/etc/apache2/mods-enabled will be a jk.load file, after restarting Apache2, Apache automatically
Load this file to load the MOD_JK.
Edit JK's configuration file
$ cd/etc/apache2/mods-available
$ sudo vi jk.conf
Enter the following:
# indicate the location of the working file Workers.properties required for the MOD_JK module to work
Jkworkersfile/etc/apache2/workers.properties
# Where to put JK logs
Jklogfile/var/log/mod_jk.log
# Set the JK log level [Debug/error/info]
Jkloglevel Info
# Select the log format
Jklogstampformat "[%a%b%d%h:%m:%s%Y]"
# jkoptions indicate to send SSL KEY SIZE,
Jkoptions +forwardkeysize +forwarduricompat-forwarddirectories
# Jkrequestlogformat Set the request format
Jkrequestlogformat "%w%V%T"
# Let Tomcat handle all the requests
#JkMount/* Worker1
Jkworkersfile This directive indicates the location of the worker configuration file. So what is a worker? Tomcat worker is a tomcat
Instance.
Jkmount/* Worker1 The meaning is to give all the requests to Tomcat, here I commented out, because write here is global.
We want to configure the forwarding rules based on hostname, so we don't write them here.
Next we edit workers.properties
$ sudo vi/etc/apache2/workers.properties
The contents are as follows:
Worker.list=worker1,worker2
# Set Properties for Worker1
Worker.worker1.type=ajp13
Worker.worker1.host=localhost
worker.worker1.port=8009
Worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
Worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
# Set Properties for Worker2
Worker.worker2.type=ajp13
worker.worker2.host=192.168.1.10
worker.worker2.port=8009
Worker.worker2.lbfactor=50
worker.worker2.cachesize=10
worker.worker2.cache_timeout=600
Worker.worker2.socket_keepalive=1
worker.worker2.socket_timeout=300
Here we define two workers, one locally and one on 192.168.1.10.
The worker.worker1.port=8009 8009 Port is the port where Apahce mod_jk is exchanging data with Tomcat
Configuration file. In the Tomcat directory/conf/server.xml, there should be the following line:
<!--Define an AJP 1.3 Connector on port 8009-
<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>
If your tomcat is configured with a different port, you should also modify the corresponding port number in the worker.properties.
Assume that the Apache server IP is bound to two domain names, one is blog.mysite.com and the other is bbs.mysite.com
Suppose Worker1 's Tomcat deploys a blog program, and Worker2 's Tomcat provides BBS services.
The configuration file for the Blog.mysite.com Apache virtual host is as follows:
<virtualhost *:80>
ServerAdmin [email protected]
ServerName blog.mysite.com
Jkmount/* Worker1
</VirtualHost>
The configuration file for the Bbs.mysite.com Apache virtual host is as follows:
<virtualhost *:80>
ServerAdmin [email protected]
ServerName bbs.mysite.com
Jkmount/* Worker2
</VirtualHost>
If blog.mysite.com and bbs.mysite.com are deployed under the same tomcat, that is, we have only one worker, then we
You need to include the configuration of the virtual host in the Tomcat configuration file. To modify the Tomcat directory/conf/server.xml, add the following configuration content.
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
</Host>
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
</Host>
How to resolve port access under 2.apache
Multiple hosts can be configured to resolve different domain names
How to integrate Apache2 and Tomcat under Ubuntu