Article 1 Integration of Apache and tomcat

Source: Internet
Author: User
1. Web architecture

First, explain the general Web architecture

 

Generally, there are three major parts:

★Web server: usually composed of Apache HTTP Server, ibm http server, and IIS (rarely used), which can be one or more. Enterprise applications are accessed by webserver, prevent application of the ear package and war

The package is exposed to the Internet, which increases system security and can be used to distribute user requests (in the Cluster Environment) and parse static files (such as JS, IMG, CSS, and other files) reduces application pressure (system action is used to access static files in many applications

In this way, the webserver component will use it as a dynamic resource ).

★APP server: Usually our web containers such as Tomcat, WebLogic, websphere, and JBoss. Applications run in Web containers, and generally there are multiple application servers, its link to webserver must be through the Enterprise Intranet

If it is an Internet connection, this architecture will become meaningless.

★DB server: You can see what the database server is.

In the production environment, Internet users access the system through the webserver layer. If security requirements are not very high, Intranet users can directly access the appserver, in general, enterprise employees do not attack enterprise applications. If such a person exists

We need to consider our own quality...

2. Apache + Tomcat

I description

Apache HTTP Server opensource project under Apache, is a widely used Web server components, you can download and install http://httpd.apache.org/

Ii. Installation of Apache

Experiment environment in the window directly double-click the installation program to install, in Linux, please refer to the official website guide http://httpd.apache.org/docs/2.2/install.html to write in detail.

Next to the following interface

Server name must be correctly configured. Use the computer name (ensure that the server can be pinged ):

After entering the information, continue to next

Select next after custom installation

Set the installation path without Chinese characters or spaces

Install

After the installation is complete, it will appear in the lower right corner of the screen:

Click this icon

Indicates that Apache is currently running.

Apache Information is added to the Start Menu.

 

Open the browser and enter http: // localhost. the following result is displayed:

Apache installation is successful now! Yeah...

III Apache HTTP Server Configuration

Find the conf/httpd. conf file in the installation directory, open the file, and search for the DocumentRoot field.

Modify DocumentRoot as follows:

# DocumentRoot "D:/software/apache2.2/htdocs"

DocumentRoot "D:/deployment"

Continue to modify and find

#
# This shoshould be changed to whatever you set DocumentRoot.
#

Modify <directory "D:/software/apache2.2/htdocs"> as follows:

# <Directory "D:/software/apache2.2/htdocs">
<Directory "D:/deployment">

After modification, test whether the configuration file is correct.

If it is correct, the command line window will flash.

Use the above configuration to change the Apache working file directory to the D: \ deploymentfolder, because the corresponding directory is created under the D Drive, and an index.html file is created. The index.html file under the Apache zookeeper file directory, in httpd. conf

File Settings:

#
# Directoryindex: sets the file that Apache will serve if a directory
# Is requested.
#
<Ifmodule dir_module>
Directoryindex index.html
</Ifmodule>

Create a directory as follows:

Restart Apache

Access http: // localhost

 

IV tomcat installation

Tomcat should be installed by every developer. The decompressed version of Tomcat 7 is used here.

V Integration

All preparations have been completed. Integration starts.

Apache can only parse static files (such as the newly created index.html file, but index. jsp files cannot be parsed). If dynamic files are encountered, they must be parsed by the Web Container (Tomcat here ).

How can I resolve dynamic resources to tomcat ???

Apache has a module called mod_jk. After the expression is configured, the request is passed to Tomcat through mod_jk.

Procedure:

1. Add mod_jk Module

The module name is: mod_jk-1.2.31-httpd-2.2.3.so, add it to the Apache installation directory under modules

 

 

 

2. Configure the parsing expression

 

Open the httpd. conf file and append the following content to the end of the file:

 

Loadmodule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so
Jkworkersfile CONF/workers. Properties
Jklogfile logs/mod_jk.log
<Virtualhost *>
Directoryindex index.html index.htm index. jsp index. Action
Errorlog logs/error_log.txt
Customlog logs/access_log.txt common

Jkmount/* WEB-INF ajp13
Jkmount/*. Action ajp13
Jkmount/servlet/* ajp13
Jkmount/*. jsp ajp13
Jkmount/*. Do ajp13
Jkmount/*. Action ajp13
Jkmount/*. JSON ajp13
Jkmount/webdemo/helloworld ajp13
</Virtualhost>

 

 

The configuration of this section has the following functions:

Create the worders. properties file in the conf directory. The content of the file is as follows:

Workers. tomcat_home = D:/software/apache-tomcat-7.0.53-windows-x86/Apache-Tomcat-7.0.53
PS =/
Worker. List = ajp13
Worker. ajp13.port = 8009
Worker. ajp13.host = localhost
Worker. ajp13.type = ajp13

√ Workers. tomcat_home: used to specify the location of Tomcat

√ Worker. List: Specify the Web Container ing for the job.

√ Worker. ajp13.host: Access host

√ Worker. ajp13.type: Access Protocol

Specify the port 8009 access protocol in the conf/server. xml file of the tomcat installation directory.

 

3. Deploy applications in Tomcat and access them through Apache

Create a web project through Maven and package it as webdemo. Put it in the webapps directory of Tomcat, start Tomcat, restart Apache, and access http: // localhost/webdemo.

Error! This is normal. Copy the webdemo folder under webapps to D:/deployment, copy and delete the WEB-INF folder (this part will be passed through the jkmount expression)

After the operation is complete, access http: // localhost/webdemo/again (this page directly accesses the static files under the D:/deployment directory)

Click the Link (returned by Tomcat parsing ):

 

Now, the integration is complete.

The running diagram is as follows:

The network administrator must block port 8080.

 

In the next article, we will describe the created Maven project to start with Maven quickly.

 

Article 1 Integration of Apache and tomcat

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.