The Apache Project

  • The Apache Project is a collaborative software development effort.

  • Its goal is to produce a robust, commercial-grade, free HTTP server.

  • The project is run by volunteers the Apache Group communicating and planning through the Internet.

  • Organizational support is provided by the Apache Software Foundation.

  • Home page:

http://apache.org

Foundation Myths

  • Long ago, when the Web was young, the most famous Web server in the World was called the NCSA server.

  • It was developed by Rob McCool at the National Center for Supercomputing Applications.

  • McCool left NCSA in 1994, and development of the public-domain NCSA server temporarily faltered.

  • At that time, a group of eight powerful Webmasters had developed their own extensions and bug-fixes for the NCSA server.

  • The founding Webmasters brought together by email pooled their updates.

  • Apache  came into being early in 1995. It was a series of  patches  to the NCSA code.

  • A year later, Apache was the most popular Web server.

Apache and Tomcat

  • This  lecture  is mainly a how-to guide to installing the Apache server and integrating it with the current version of Tomcat.

  • This allows a site primarily served by Apache to seamlessly make servlet and JSP content available.

Tomcat vs. Apache

The Apache Web server

    • is faster than Tomcat when it comes to static pages,
    • is more configurable than Tomcat,
    • is more robust than Tomcat, and
    • it supports CGI scripts, Server API modules, Perl, PHP, etc.

Hence for real world sites, Apache would generally be a better choice than Tomcat, except that. . .

    • In itself, Apache doesn t support Servlets or JavaServer Pages!

Integrating Apache and Tomcat

The solution, of course, is to allow the two Web servers to work together.

The Apache server will be the principal server, dealing with static documents.

Or dynamic documents generated by any of the other technologies mentioned in the previous slide.
Apache will forward requests for Servlets or JavaServer Pages to Tomcat.

The approach we describe here is what was called the out-of-process servlet container the lectures on Servlets.

The Adapter

For Apache to communicate with Tomcat, and forward requests as necessary, it needs some extra software an adapter.

An adapter will be implemented as an Apache module.

An Apache module is a piece of code that can be optionally linked in to (or left out of) the main server code.
Non-standard, plug-in, modules will typically be shared-object libraries (DLLs under Windows).
These live in a directory called /usr/local/apache/libexec.
Apache modules generally have names of the form mod_XXXX

For example, mod_perl.
There are two Tomcat adapter modules in common use: mod_jserv and mod_jk.

mod_jk

mod_jk is a new Tomcat-Apache plug-in that handles communication between Tomcat and Apache.

It replaces the older mod_jserv.
For more information, see the file doc/mod_jk-howto.html in the Tomcat release, which is also online at

jakarta.apache.org/tomcat/jakarta-tomcat/src/doc/mod_jk-howto.html

For now the only way to obtain the mod_jk library for Linux seems to be to build it yourself. The sources are included in the source release of Tomcat.

Obtaining mod_jk for Linux

Go to jakarta.apache.org and follow the Source Code link.

Get the release build of Tomcat (currently 3.2). At the time of writing, the relevant file is

jakarta-tomcat-3.2-src.tar.gz
Unpack the distribution:

gunzip -c jakarta-tomcat-3.2-src.tar.gz | tar xvf -
You can do this anywhere, e.g. in /tmp.
I do not particularly recommend you try to rebuild the Tomcat server itself from this release: it is much easier just to download the compiled, binary version of the server, as described in the lectures on Servlets.

Building mod_jk

Go to the directory

jakarta-tomcat-3.2-src/src/native/apache1.3
If necessary, edit the definition of the macro APXS in Makefile.linux so that it refers to the apxs command in the Apache release, probably /usr/local/apache/bin/apxs.

Build the library:

make -f Makefile.linux
Install the plug-in in the Apache libexec/ directory, e.g.:

cp mod_jk.so /usr/local/apache/libexec

Updating the Apache Configuration

In the first instance (until you need to do something clever) this is very easy, because whenever the Tomcat server is run, it generates a self-describing include file.

This file contains a series of Apache configuration-file commands.
The include file is in

jakarta-tomcat-X.X/conf/mod_jk.conf-auto
In my case I added the line

include /home/users/dbc/jakarta-tomcat-3.2/conf/mod_jk.conf-auto

to the end of the file /usr/local/apache/conf/httpd.conf.

Fragment of the File mod_jk.conf-auto

#########################################################

# Auto configuration for the /dbc context starts.

#########################################################

# The following line makes apache aware of the location of the /dbc context

Alias /dbc "/home/users/dbc/jakarta-tomcat-3.2/webapps/dbc"

<Directory "/home/users/dbc/jakarta-tomcat-3.2/webapps/dbc">

Options Indexes FollowSymLinks

</Directory>

# The following line mounts all JSP files and the /servlet/ uri to tomcat

JkMount /dbc/servlet/* ajp12

JkMount /dbc/*.jsp ajp12

# The following line prohibits users from directly accessing WEB-INF

<Location "/dbc/WEB-INF/">

AllowOverride None

deny from all

</Location>

# The following line prohibits users from directly accessing META-INF

<Location "/dbc/META-INF/">

AllowOverride None

deny from all

</Location>

Remarks

Recall these are commands that Tomcat generates to configure Apache.

As the first comments indicates, these commands relate to the servlet context called dbc/.

The Alias command causes Apache to generally look in the Tomcat document directory for URLs with paths that start /dbc.

This is needed for static documents in the Tomcat directory.
The first JkMount command causes URLs with paths that match the pattern /dbc/servlet/* to be redirected to the AJP module (hence the Tomcat server).

The second JkMount command causes URLs with paths that match the pattern /dbc/*.jsp to be similarly redirected Tomcat server.

Configuring Workers

In Tomcat 3.2, the generated include file, jakarta-tomcat-X.X/conf/mod_jk.conf-auto has a reference to the file workers.properties in the same directory. You will probably have to manually edit this file.

Enclosed comments are fairly self-explanatory. If necessary change the Java home directory and the path-component separator (to / rather than \ for Linux).

You may also need to choose one or the other of ajp12 and ajp13, and comment out references to the other.

I went with ajp12. ajp13 is supposed to be an improved protocol, but I know and love ajp12.
Set the port number for your AJP connector, as specified in server.xml.

See jakarta-tomcat-X.X/doc/Tomcat-Workers-HowTo.html.

Start the Apache Server. . .

In principle, we are done. Restart the Apache server.

With the default configuration, URLs with paths in Tomcat servlet contexts that start /servlet or end with .jsp are redirected to Tomcat.

Note Apache will directly serve static .html pages, even if they are in the Tomcat document directory.
Because Apache (unlike Tomcat) runs as user nobody by default, such files now need to be world readable.
(Apparently) things continue to work across multiple restarts of Tomcat, even without restarting Apache.

We note however that, according to the FAQ, this is not the case with AJP13. . .

What is the difference Apache (Http Server) and Tomcat (Servlet Container)的更多相关文章

  1. Apache Http Server和Tomcat 之区别

    转自:Apache Http Server和Tomcat 之区别 Apache官方网站:http://www.apache.org/Tomcat官方网站:http://tomcat.apache.or ...

  2. [转]Apache HTTP Server 与 Tomcat 的三种连接方式介绍

    首先我们先介绍一下为什么要让 Apache 与 Tomcat 之间进行连接.事实上 Tomcat 本身已经提供了 HTTP 服务,该服务默认的端口是 8080,装好 tomcat 后通过 8080 端 ...

  3. 转自IBM:Apache HTTP Server 与 Tomcat 的三种连接方式介绍

    http://www.ibm.com/developerworks/cn/opensource/os-lo-apache-tomcat/index.html 整合 Apache Http Server ...

  4. Apache HTTP Server与Tomcat整合学习记录

    Apache HTTP Server与Tomcat整合 个人环境:Windows10,JDK8,Tomcat8.5,Apache2.4,JK模块1.2.4 前言 ​ 其实网上有很多教程,但问题是得每次 ...

  5. Windows 下 Apache HTTP Server 与 Tomcat 的整合

    整合准备: 1.Apache HTTP Server(下文用Apache简称) 2.Tomcat 7或8 3.mod_jk.so (tomcat-connectors)-这个文件是用来链接http s ...

  6. Apache http server和tomcat的区别

    Apache官方网站:http://www.apache.org/Tomcat官方网站:http://tomcat.apache.org/ 1. Apache是web服务器,Tomcat是应用(jav ...

  7. apache http server 和tomcat的区别 以及nginx

    Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器. 要明白他们之间的区别,我们首先需要明白HTTP协议.HTML页面.JSP.Servlet之 ...

  8. Apache HTTP Server 与 Tomcat 的三种连接方式介绍(转)

    首先我们先介绍一下为什么要让 Apache 与 Tomcat 之间进行连接.事实上 Tomcat 本身已经提供了 HTTP 服务,该服务默认的端口是 8080,装好 tomcat 后通过 8080 端 ...

  9. Apache HTTP Server 与 Tomcat 的三种连接方式介绍

    本文转载自IBM developer 首先我们先介绍一下为什么要让 Apache 与 Tomcat 之间进行连接.事实上 Tomcat 本身已经提供了 HTTP 服务,该服务默认的端口是 8080,装 ...

随机推荐

  1. uploader上传

    综述 Uploader是非常强大的异步文件上传组件,支持ajax.iframe.flash三套方案,实现浏览器的全兼容,调用非常简单,内置多套主题支持和常用插件,比如验证.图片预览.进度条等. 广泛应 ...

  2. HTML5自学笔记[ 9 ]HTML5实现元素的拖放

    要想在html5中实现元素的拖放,被拖放元素就必须设置属性draggable="true";被拖放元素被放置的地方是另外一个元素,该元素是目标元素:这两个元素在拖放过程中都会触发不 ...

  3. 如何使用java调用DLL运行C++(初篇)

    JNI:Java Native Interface,简称JNI,是Java平台的一部分,可用于让Java和其他语言编写的代码进行交互. 下面是从网上摘取的JNI工作示意图:

  4. IO流--切割 合并文件

    import java.io.*; import java.util.*; public class io { public static void main(String[] args)throws ...

  5. Java 之 I/O 系列 02 ——序列化(一)

    Java 之 I/O 系列 目录 Java 之 I/O 系列 01 ——基础 Java 之 I/O 系列 02 ——序列化(一) Java 之 I/O 系列 02 ——序列化(二) 一 序列化概述 序 ...

  6. python获取文件的内容

  7. POJ 3206 最小生成树

    DESCRIPTION:T_T 在下是读不懂题意的.但是捏.现在知道是求把所有的点(是字母的点)连起来的最小的权值.即最小生成树.因为求最小生成树是不计较源点是哪个的.所以可以把A和S看成一样的.首先 ...

  8. 高效前端优化工具--Fiddler入门教程

    简介: Fiddler是用C#编写的一个免费的HTTP/HTTPS网络调试器.Fiddler是以代理服务器的方式,监听系统的网络数据流动英语中Fiddler是小提琴的意思,Fiddler Web De ...

  9. HTTP协议的chunked编码

    一般情况HTTP的Header包含Content-Length域来指明报文体的长度.如: 有时候服务生成HTTP回应是无法确定消息大小的,比如大文件的下载,或者后台需要复杂的逻辑才能全部处理页面的请求 ...

  10. Fair Photography

    题目大意: 给出直线上N个点的位置和颜色(0或1),求最大的区间,使得区间内0的个数大于等于1的个数且0的个数减去1的个数为偶数. 解题过程: 1.先贴个lsdsjy大牛的线段树的做法:http:// ...