**apache Integrated Tomcat Instance

Source: Internet
Author: User
Tags server port tomcat server

1.Apache Why do you want to integrate Tomcat?

In fact, Tomcat itself already provides the HTTP service, the default port is 8080, after the Tomcat is installed through 8080 ports can directly use Tomcat run the application, you can also change the port to 80.

Since Tomcat itself can provide such services, why do we have to introduce Apache or some other specialized HTTP server? For the following reasons:

1). Enhance the processing performance of static files

2. Use Web server to do load balancing and fault tolerance

3). Seamless Upgrade Application

These three points are very important to a Web site, we want our site to be not only fast, but also stable, not because of a tomcat downtime or upgrade program to cause users can not access, but to complete these functions, the best HTTP server is only Apache HTTP Server, it is the closest and most reliable combination of Tomcat.

2.Apache three ways to blend Tomcat

Jk

Http_proxy

Ajp_proxy

The differences and benefits of these three approaches are detailed in the following: http://www.ibm.com/developerworks/cn/opensource/os-lo-apache-tomcat/

How 3.**apache and Tomcat are integrated

**apache integrated Tomcat uses the classic JK model. The JK module communicates with the Tomcat server through the AJP protocol, and the port of the Tomcat default AJP connector is 8009.

* * Test environment is forwarded using Apache (1) +tomcat (N), which is the next Apache for request forwarding in the root account, each configured with a TOMCAT deployment-related application.

The configuration steps are as follows (in **# #系统为例):

Apache installation directory:/opt/httpd-2.2.14/

Tomcat installation directory:/home/jd-lottery/jd-lottery

(1) Add mod_jk.so to/opt/httpd-2.2.14/modules

(2) Add the following configuration under/opt/httpd-2.2.14/conf/httpd.conf (another two profiles are introduced)

# Virtual Hosts

Include conf/extra/httpd-jk.conf

Include conf/extra/httpd-vhosts.conf

(3) Configure the following content in the httpd-jk.conf

</Directory>

#<location/jkstatus>

# Order Deny,allow

# Deny from all

#</location>

#载入监控模块

LoadModule Jk_module modules/mod_jk.so

#到Tomcat服务器的连接定义文件

Jkworkersfile "Conf/workers.properties"

#URI映射文件, to specify which URLs are handled by Tomcat, you can also configure these URIs directly in httpd.conf, but the advantage of being independent of these configurations is that the JK module periodically updates the contents of the file, allowing us to modify the configuration without restarting the Apache server

Jkmountfile "Conf/uriworkermap.properties"

Jklogfile Logs/mod_jk.log

Jkloglevel warn

(4) under the/opt/httpd-2.2.14/conf/workers.properties under the following configuration

# list the workers by name

Worker.list=status, Jd-caipiao

# Status Monitor the state of the JK itself

Worker.status.type=status

# ------------##------------

worker.jd-caipiao.port=8743

worker.jd-caipiao.host=127.0.0.1

Worker.jd-caipiao.type=ajp13

(5) Under the httpd-vhosts.conf under the following configuration

Namevirtualhost *:80

<virtualhost *:80>

DocumentRoot "/home/jd-lottery/jd-lottery-web.war"

ServerName caipiao.360buy.net

Serveralias caipiao.360buy.com

<directory "/home/jd-lottery/jd-lottery-web.war" >

Options-indexes +followsymlinks

AllowOverride None

Order Allow,deny

Allow from all

</Directory>

<ifmodule dir_module>

DirectoryIndex index.html index.htm

</IfModule>

Jkmountfile "Conf/jd-caipiao-uriworkermap.properties"

</VirtualHost>

<virtualhost *:80>

DocumentRoot "/home/jd-lottery/jd-lotteryman-web.war"

ServerName man.caipiao.360buy.net

Serveralias man.caipiao.360buy.com

<directory "/home/jd-lottery/jd-lotteryman-web.war" >

Options-indexes +followsymlinks

AllowOverride None

Order Allow,deny

Allow from all

</Directory>

<ifmodule dir_module>

DirectoryIndex index.html index.htm

</IfModule>

Jkmountfile "Conf/jd-caipiao-uriworkermap.properties"

</VirtualHost>

(6) The following configuration is done in the/opt/httpd-2.2.14/conf/jd-caipiao-uriworkermap.properties

/*=jd-caipiao

/*.jsp=jd-caipiao

/*.action=jd-caipiao

(7) Configuration of virtual host and APJ port in Tomcat

The/home/jd-lottery/jd-lottery/conf/server.xml configuration is as follows:

<?xml version= "1.0" encoding= "Utf-8"?>

-<server port= "8741" shutdown= "Shutdown" >

<listenerclassname= "Org.apache.catalina.core.AprLifecycleListener" sslengine= "on"/>

<listenerclassname= "Org.apache.catalina.core.JasperListener"/>

<listenerclassname= "Org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

<listenerclassname= "Org.apache.catalina.mbeans.ServerLifecycleListener"/>

<listenerclassname= "Org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

-<globalnamingresources>

<resourcename= "Userdatabase" auth= "Container" type= "Org.apache.catalina.UserDatabase" description= "User Database that can is updated and saved "factory=" Org.apache.catalina.users.MemoryUserDatabaseFactory "Pathname=" conf/ Tomcat-users.xml "/>

</GlobalNamingResources>

-<service name= "Catalina" >

<!---HTTP protocol listening port, defaults to 8080->

<connectorport= "8742" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443" URIEncoding= "GBK" Usebodyencodingforuri= "true"/>

<!--APJ protocol listening port, Apache via this port and Tomcat communication-->

<connectorport= "8743" protocol= "ajp/1.3" redirectport= "8443" uriencoding= "GBK" usebodyencodingforuri= "true"/ >

-<engine name= "Catalina" defaulthost= "localhost" >

<realmclassname= "Org.apache.catalina.realm.UserDatabaseRealm" resourcename= "Userdatabase"/>

<!--the configuration of the virtual host, the configuration should be httpd-vhosts.conf with the corresponding-->

-

<Alias>man.caipiao.360buy.com</Alias>

</Host>

</Engine>

</Service>

</Server>

(8) Tomcat Setup virtual directory

There are three ways to configure Tomcat virtual directories, * * The main test environment is to add a Catalina directory under the/HOME/JD-LOTTERY/JD-LOTTERY/CONF directory structure as follows:

Catalina/lottery.360buy.net/root.xml, the contents are as follows:

<context path= "" docbase= "/home/jd-lottery/work/test/lottery"/>

Catalina/man.caipiao.360buy.net/root.xml, the contents are as follows:

<context path= "" docbase= "/home/jd-lottery/jd-lotteryman-web.war"/>

Note:

(1) The Apache default publishing directory is:%apache_home%\htdocs

How to modify the default publishing directory:

Modify configuration file: httpd.conf
DocumentRoot "D:/apache2.2.4/htdocs" modified to "D:/htdocs"
<directory "D:/apache2.2.4/htdocs" >
Order Allow,deny
Allow from all
</Directory>
Amended to
<directory "D:/htdocs" >
Order Allow,deny
Allow from all
</Directory>

However, it should be noted that if a virtual host is configured, include conf/extra/is turned on HTTPD-VHOSTS.CONF functionality, the way in which the httpd.conf is configured is invalidated, and the following configuration can be added to the httpd-vhost.conf:

<virtualhost *:80>

DocumentRoot "D:/htdocs"
ServerName Log

<directory "D:/htdocs" >
Order Allow,deny
Allow from all
</Directory>

</VirtualHost>

To open the Catalog Publishing feature.

(2)/opt/httpd-2.2.14/logs/access_log can see the amount of access per visit.

(3) If the Apache startup is unsuccessful, you can use Apache HTTP Server 2.2.4-->configure Apache server-->test configuration detect which configuration file is out of the question.

(4) Add the function of JK Monitoring, add the following configuration in httpd-vhosts.conf (also can share other virtual host)

<virtualhost *:80>

DocumentRoot "D:/htdocs"
ServerName localhost

<directory "D:/htdocs" >
Order Allow,deny
Allow from all
</Directory>

<Location/jkstatus>
Jkmount status
Order Deny,allow
</Location>

Jkmountfile "Conf/uriworkermap.properties"
</VirtualHost>

Add the following configuration to the Conf/uriworkermap.properties:

/jkstatus=status

Participating Documents:

(1) http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html This is JK's official website document.

(2) http://www.ibm.com/developerworks/cn/opensource/os-lo-apache-tomcat/This is a summary nature of the IBM Web site document.

(3) Http://wenku.baidu.com/view/6b08654ffe4733687e21aa1d.html This is a Baidu library to explain PPT.

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.