Windows 下APACHE2.2.x+Tomcat6.0+HOST虚拟主机配置

假设:服务器通过tomcat6.0使用8080端口对外提供服务,Apache2.2.14提供负载均衡,通过使用AJP 1.3 实现负载均衡

  1. 下载文件:

(1)       apache2.2.14  下载地址:http://apache.org

(2)       Tomcat 6.0.26

(3)       Tomcat connectors JK1.2.30 下载地址:http://apache.etoak.com/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.30/mod_jk-1.2.30-httpd-2.2.3.so

  1. 配置过程:
  1. 安装apache服务器,一路下一步就OK
  2. 配置apache服务器:

1)  打开%apacheRoot%/conf/httpd.conf,修改网站根目录等

2)  在配置文件<IfModule dir_module>

DirectoryIndex index.html

</IfModule>
index.html后面增加 index.jsp等后缀,用空格分隔

  1. 将mod_jk-1.2.30-httpd-2.2.3.so改名为mod_jk.so(为了方便)并复制到%apacheRoot%/modules下
  2. 在%apacheRoot%/conf下建立workers.properties文件,并写入以下内容:

#下面是Tomcat实例列表即不同的Tomcat服务器

worker.list=tomcat1

#tomcat1 实例配置,此实例的名字就叫做tomcat1

worker.tomcata.host=localhost

worker.tomcata.port=8009

worker.tomcata.type=ajp13

  1. 打开httpd.conf 在最后添加:

LoadModule jk_module ” modules/mod_jk.so”

# Where to find workers.properties

JkWorkersFile ” conf/workers.properties”

# Where to put jk logs

JkLogFile ” 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”

JkMount /*.jsp        tomcat1

# 转发某个目录下的(此例为:/example)所有文件给tomcat:

JkMount /example/*  tomcat1

启动Apache 和Tomcat,打开浏览器输入:http://localhost/example

  1. 配置虚拟主机:
    1)配置apache的虚拟主机:
    打开httpd.conf将#Include “conf/extra/httpd-vhosts.conf”前面的#去掉
    打开%apacheRoot%/ conf/extra/httpd-vhosts.conf增加一个虚拟主机:

<VirtualHost *:80>

ServerAdmin webmaster@example.com

DocumentRoot “D:/www/example”

ServerName example.com

ServerAlias www.example.com

ErrorLog “logs/dummy-host2.example.com-error.log”

CustomLog “logs/dummy-host2.example.com-access.log” common

<Directory “D:/www/example”>

Options Indexes FollowSymLinks

AllowOverride Options FileInfo

Order allow,deny

Allow from all

DirectoryIndex index.htm index.html index.php index.jsp

</Directory>

<Location /server-status>  # 这样可以看到apache服务器状态

SetHandler server-status

Order deny,allow

Deny from all

Allow from example.com

Allow from www.example.com

</Location>

</VirtualHost>

2)配置tomcat下的虚拟机:

打开%tomcatRoot%/conf/server.xml,在<Engine></Engine>中间增加:
<Host name=”www.example.com” appBase=”D:\www\example”

unpackWARs=”true” autoDeploy=”true”

xmlValidation=”false” xmlNamespaceAware=”false”> </Host>

测试配置:

  1. 在D:\www\example下新建文件夹ROOT ,在ROOT中新建:index.jsp:

<html>

  <head>

    <title>JSP 2.0 Expression Language – Basic Arithmetic</title>

  </head>

  <body>

    <h1>JSP 2.0 Expression Language – Basic Arithmetic</h1>

    <hr>

    This example illustrates basic Expression Language arithmetic.

    Addition (+), subtraction (-), multiplication (*), division (/ or div),

    and modulus (% or mod) are all supported.  Error conditions, like

    division by zero, are handled gracefully.

    <br>

    <blockquote>

      <code>

        <table border=”1″>

          <thead>

            <td><b>EL Expression</b></td>

            <td><b>Result</b></td>

          </thead>

          <tr>

            <td>\${1}</td>

            <td>${1}</td>

          </tr>

          <tr>

            <td>\${1 + 2}</td>

            <td>${1 + 2}</td>

          </tr>

          <tr>

            <td>\${1.2 + 2.3}</td>

            <td>${1.2 + 2.3}</td>

          </tr>

          <tr>

           <td>\${1.2E4 + 1.4}</td>

            <td>${1.2E4 + 1.4}</td>

          </tr>

          <tr>

            <td>\${-4 – 2}</td>

            <td>${-4 – 2}</td>

          </tr>

          <tr>

            <td>\${21 * 2}</td>

            <td>${21 * 2}</td>

          </tr>

          <tr>

            <td>\${3/4}</td>

            <td>${3/4}</td>

          </tr>

          <tr>

            <td>\${3 div 4}</td>

            <td>${3 div 4}</td>

          </tr>

          <tr>

            <td>\${3/0}</td>

            <td>${3/0}</td>

          </tr>

          <tr>

            <td>\${10%4}</td>

            <td>${10%4}</td>

          </tr>

          <tr>

            <td>\${10 mod 4}</td>

            <td>${10 mod 4}</td>

          </tr>

    <tr>

      <td>\${(1==2) ? 3 : 4}</td>

      <td>${(1==2) ? 3 : 4}</td>

    </tr>

        </table>

      </code>

    </blockquote>

  </body>

</html>

  1. 修改Host文件或者DNS:

修改C:\windows\system32\drivers\ect\host,增加一行:

127.0.0.1                 example.com

  1. 重启Tomcat和Apache,打开浏览器输入:example.com

如果出现以下页面,恭喜你,成功了!

此条目发表在服务器分类目录。将固定链接加入收藏夹。