Apache integrates Tomcat and resin

Source: Internet
Author: User

Apache integrates Tomcat and resin

For details about how to compile and install Apache and JDK tomcat resin, refer to my JSP and cluster architecture modules; the two types of integration require the Apache call module mod_jk.so and mod_caucho.so to integrate them;

----------------------------- Apache integration tomcat ----------------------------------

1. Introduction

Apache supports static pages, while tomcat supports dynamic pages, such as servlets.

Apache supports php \ cgi \ perl, but if you want to use java, you need tomcat to support it in the apache background. apache forwards the java request to tomcat for processing.

Apache is a web server, and Tomcat is an application (java) server. It is just a servlet (jsp is also translated into servlet) container. It can be considered as an extension of apache, but it can run independently of apache.

2. After installing and compiling Apache · JDK and tomcat

Download jakarta-tomcat-connectors-1.2.15-src.tar.gz from the same official website

3. compile and generate mod_jk

# Tar xzvf jakarta-tomcat-connectors-1.2.15-src.tar.gz

# Cd jakarta-tomcat-connectors-1.2.15-src/jk/native

#./Configure -- with-apxs =/usr/local/apache2/bin/apxs

# Make

# Cp./apache-2.0/mod_jk.so/usr/local/apache2/modules/

4. Configure the Apache configuration file (virtual host configuration file)

Create two configuration files mod_jk.conf and workers. properties under/usr/local/apache2/conf.

# Vi mod_jk.conf

Add the following content:
# Point out the location of the workers. properties file required for mod_jk module work
JkWorkersFile/usr/local/apache2/conf/workers. properties
# Where to put jk logs
JkLogFile/usr/local/apache2/logs/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"
# Send all servlet and jsp requests to Tomcat through the ajp13 protocol for Tomcat to process
JkMount/servlet/* worker1
JkMount/*. jsp worker1

# Vi workers. properties

Add the following content:
# Defining a worker named worker1 and of type ajp13
Worker. list = worker1
# 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

Configure httpd. conf and make the following changes:

Change Listen 80 to Listen 127.0.0.1: 80

Change ServerName to ServerName LocalHost: 80

5. Test

Add index. jsp to DirectoryIndex

My webpage is stored in/var/wwwroot, So modify DocumentRoot

DocumentRoot "/var/wwwroot"
<Directory "/var/wwwroot">
Options shortdes FollowSymLinks
AllowOverride None
Order deny, allow
Allow from all
XBitHack on
</Directory>
<Directory "/var/wwwroot/WEB-INF">
Order deny, allow
Deny from all
</Directory>

Add the statement about loading mod_jk:

LoadModule jk_module modules/mod_jk.so

Include/usr/local/apache2/conf/mod_jk.conf

6. Finally, edit the Tomcat configuration file server. xml and add the following to the HOST segment:

<Context path = "" docBase = "/var/wwwroot" debug = "0" reloadable = "true" crossContext = "true"/>

Create an index. jsp in/var/wwwroot: 2 + 2 = <% = 2 + 2%>

Start Apache and Tomcat and access http: // localhost/in a browser. You can see 2 + 2 = 4.

Load cluster implementation:

Practice of Enterprise Web high availability cluster integration with Apache Tomcat for Tomcat Load Balancing cluster + Session

---------------------------------- Apache integrated resin -------------------------------

Install the mod_so.c module when installing and compiling Apache, specifying that DSO is supported;

1. If it is not supported, or you want to reinstall a new apache, you can use the source code to re-compile

#./Configure -- prefix =/usr/local/apache -- enable-module = so

# Make

# Make install

2. Compile the mod_caucho.so Module

Decompress the resin source code. (install JDK and set JDK before compiling RESIN)

#./Configure -- with-apxs =/usr/local/apache/bin/apxs

# Make

# Make install

If you do not know the path of apxs, use #./configure -- with-apache =/usr/local/apache.

You can also specify the apache path.

3. Set resin. conf

Compile the resin configuration file. Modify the bold part.

# Vi conf/resin. conf

<Cluster>
<Srun server-id = "" host = "127.0.0.1" port = "6802" type = "codeph" text = "/codeph"/>
</Cluster>
# Server-id can be defined by yourself. If resin is not on the same machine as apache, change the host to the resin ip address and port.
# Set the default document directory of resin to the same directory as apache DocumentRoot.
<Host id = "">
<Web-app id = '/' document-directory = "/usr/local/apache/htdocs"/>
</Host>

Start resin

4. Test

Compile a jsp file to test whether resin is normal

Create a file

# Vi/usr/local/apache/htdocs/test. jsp

2 + 2 = <% = 2 + 2%>

In the browser, browse [url] http: // localhost: 8080/test. jsp [/url]. If you can see 2 + 2 = 4

It indicates that after resin successfully modifies apache settings and compiles resin, the httpd. conf of apache will be automatically modified and the following content will be added,

If not, manually add the following content:

LoadModule caucho_module libexec/mod_caucho.so

ResinConfigServer localhost 6802.

<Location/caucho-status>

SetHandler caucho-status

</Location>

Restart apache and the backend resin to test the jsp and html files again. If http: // localhost/test. jsp shows the page, the configuration is successful.

For more Tomcat tutorials, see the following:

Install and configure the Tomcat environment in CentOS 6.6

Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects

Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)

Tomcat Security Configuration and Performance Optimization

How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux

Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure

Install Tomcat in CentOS 6.5

Tomcat details: click here
Tomcat: click here

This article permanently updates the link address:

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.