Tomcat集群apache摘要认证https加密
1.环境准备:
· linux虚拟机两个【一个也行,这是为了更好的测试】
· JDK1.7左右
· tomcat7.0两个以上:http://tomcat.apache.org/download-70.cgi下载如图所示:
· httpd-2.2.27.tar.gz:http://httpd.apache.org/download.cgi下载如图所示:
· openssl-1.0.1g.tar.gz:http://www.openssl.org/source/openssl-1.0.1g.tar.gz
2. 软件安装
2.1错误集中地
· ERROR1安装gcc:【yum install gcc】在服务器任意地方直接copy这段语句运行(它会问你y/N,回答它y)。
错误为:configure: error: in`/root/httpd-2.2.27/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
configure failed for srclib/apr
· ERROR2安装zlib:【yum install zlib-devel -y】在服务器任意地方直接copy这段语句运行。
错误为:checking for zliblocation... not found
2.2 安装 openssl
tar zxf openssl-1.0.1g.tar.gz
cd openssl-1.0.1g
./config--prefix=/home/admin/app/openssl
make;make install
如果出现
./configure --prefix=/ytxt/apache2/ --enable-ssl --enable-rewrite --enable-so --with-ssl=/usr/local/openssl/
报错:
configure: error: ... Error, SSL/TLS libraries were missing or unusable
在服务器上执行 export LDFLAGS=-ldl
2.3 安装apache httpd
你需要按照如下方式进行(配置有可能出ERROR1与ERROR2,解决这两个错误之后请重新把配置语句执行一遍):
· 使用root用户(最好是root)上传:httpd-2.2.27.tar.gz
· 解压:tar -xvfhttpd-2.2.27.tar.gz
- ①配置:./configure --prefix=/usr/local/apache2 --enable-modules=so --enable-mods-shared=most --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-rewrite --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl
· 制作:make
· 安装:make install
· Over,安装完成。
3. 软件配置
3.1 tomcat配置
· tomcat_A,配置server.xml(${tomcatHome}/conf/server.xml),我的配置是:
1. <!--
2. Licensed to the Apache Software Foundation (ASF) under one or more
3. contributor license agreements. See the NOTICE file distributed with
4. this work for additional information regarding copyright ownership.
5. The ASF licenses this file to You under the Apache License, Version 2.0
6. (the "License"); you may not use this file except in compliance with
7. the License. You may obtain a copy of the License at
8.
9. http://www.apache.org/licenses/LICENSE-2.0
10.
11. Unless required by applicable law or agreed to in writing, software
12. distributed under the License is distributed on an "AS IS" BASIS,
13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14. See the License for the specific language governing permissions and
15. limitations under the License.
16.-->
17.<!-- Note: A "Server" is not itself a "Container", so you may not
18. define subcomponents such as "Valves" at this level.
19. Documentation at /docs/config/server.html
20. -->
21.<Server port="8005" shutdown="SHUTDOWN">
22. <!-- Security listener. Documentation at /docs/config/listeners.html
23. <Listener className="org.apache.catalina.security.SecurityListener" />
24. -->
25. <!--APR library loader. Documentation at /docs/apr.html -->
26. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
27. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
28. <Listener className="org.apache.catalina.core.JasperListener" />
29. <!-- Prevent memory leaks due to use of particular java/javax APIs-->
30. <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
31. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
32. <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
33.
34. <!-- Global JNDI resources
35. Documentation at /docs/jndi-resources-howto.html
36. -->
37. <GlobalNamingResources>
38. <!-- Editable user database that can also be used by
39. UserDatabaseRealm to authenticate users
40. -->
41. <Resource name="UserDatabase" auth="Container"
42. type="org.apache.catalina.UserDatabase"
43. description="User database that can be updated and saved"
44. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
45. pathname="conf/tomcat-users.xml" />
46. </GlobalNamingResources>
47.
48. <!-- A "Service" is a collection of one or more "Connectors" that share
49. a single "Container" Note: A "Service" is not itself a "Container",
50. so you may not define subcomponents such as "Valves" at this level.
51. Documentation at /docs/config/service.html
52. -->
53. <Service name="Catalina">
54.
55. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
56.
57. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
58. maxThreads="500" minSpareThreads="20" maxIdleTime="60000"/>
59.
60. <!-- A "Connector" represents an endpoint by which requests are received
61. and responses are returned. Documentation at :
62. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
63. Java AJP Connector: /docs/config/ajp.html
64. APR (HTTP/AJP) Connector: /docs/apr.html
65. Define a non-SSL HTTP/1.1 Connector on port 8080
66. -->
67. <!--
68. <Connector port="8080" protocol="HTTP/1.1"
69. connectionTimeout="20000"
70. redirectPort="8443" />
71. -->
72. <!-- A "Connector" using the shared thread pool-->
73.
74. <Connector executor="tomcatThreadPool"
75. port="8080" protocol="HTTP/1.1"
76. connectionTimeout="20000"
77. redirectPort="8443" URIEncoding="UTF-8" acceptCount="256"/>
78.
79. <!-- Define a SSL HTTP/1.1 Connector on port 8443
80. This connector uses the JSSE configuration, when using APR, the
81. connector should be using the OpenSSL style configuration
82. described in the APR documentation -->
83. <!--
84. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
85. maxThreads="150" scheme="https" secure="true"
86. clientAuth="false" sslProtocol="TLS" />
87. -->
88.
89. <!-- Define an AJP 1.3 Connector on port 8009 -->
90. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
91.
92.
93. <!-- An Engine represents the entry point (within Catalina) that processes
94. every request. The Engine implementation for Tomcat stand alone
95. analyzes the HTTP headers included with the request, and passes them
96. on to the appropriate Host (virtual host).
97. Documentation at /docs/config/engine.html -->
98.
99. <!-- You should set jvmRoute to support load-balancing via AJP ie : -->
100. <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat_A">
101. <!-- <Engine name="Catalina" defaultHost="localhost"> -->
102.
103. <!--For clustering, please take a look at documentation at:
104. /docs/cluster-howto.html (simple how to)
105. /docs/config/cluster.html (reference documentation) -->
106. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
107. <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false"
108. notifyListenersOnReplication="true" />
109. <Channel className="org.apache.catalina.tribes.group.GroupChannel" >
110. <Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45564" frequency="500" dropTime = "3000"/>
111. <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4000" autoBind="100" selectorTimeout="5000" maxThreads = "6" />
112. <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter" >
113. <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
114. </Sender>
115. <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
116. <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
117. </Channel>
118. <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
119. <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
120. <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/"
121. watchDir="/tmp/war-listen/" watchEnabled = "false"/>
122. <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
123. <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
124. </Cluster>
125.
126. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
127. via a brute-force attack -->
128. <Realm className="org.apache.catalina.realm.LockOutRealm">
129. <!-- This Realm uses the UserDatabase configured in the global JNDI
130. resources under the key "UserDatabase". Any edits
131. that are performed against this UserDatabase are immediately
132. available for use by the Realm. -->
133. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
134. resourceName="UserDatabase"/>
135. </Realm>
136.
137. <Host name="localhost" appBase="webapps"
138. unpackWARs="true" autoDeploy="true">
139.
140. <!-- SingleSignOn valve, share authentication between web applications
141. Documentation at: /docs/config/valve.html -->
142. <!--
143. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
144. -->
145.
146. <!-- Access log processes all example.
147. Documentation at: /docs/config/valve.html
148. Note: The pattern used is equivalent to using pattern="common" -->
149. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
150. prefix="localhost_access_log." suffix=".txt"
151. pattern="%h %l %u %t "%r" %s %b" />
152.
153. </Host>
154. </Engine>
155. </Service>
156.</Server>
以上server.xml中,请重点关注以下两点:
⑴<Enginename="Catalina" defaultHost="localhost"jvmRoute="tomcat_A">
把jvmRoute改成你想象中的名字
⑵Cluster加上这个节点中的所有内容,address="auto"这个默认会读取你的本机IP地址,如果你的机器IP地址设置有问题,你可以自己手动修改成本机地址,如address="192.168.0.27"。
· tomcat_B,配置server.xml(${tomcatHome}/conf/server.xml),我的配置是:
1. <?xml version='1.0' encoding='utf-8'?>
2. <!--
3. Licensed to the Apache Software Foundation (ASF) under one or more
4. contributor license agreements. See the NOTICE file distributed with
5. this work for additional information regarding copyright ownership.
6. The ASF licenses this file to You under the Apache License, Version 2.0
7. (the "License"); you may not use this file except in compliance with
8. the License. You may obtain a copy of the License at
9.
10. http://www.apache.org/licenses/LICENSE-2.0
11.
12. Unless required by applicable law or agreed to in writing, software
13. distributed under the License is distributed on an "AS IS" BASIS,
14. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15. See the License for the specific language governing permissions and
16. limitations under the License.
17.-->
18.<!-- Note: A "Server" is not itself a "Container", so you may not
19. define subcomponents such as "Valves" at this level.
20. Documentation at /docs/config/server.html
21. -->
22.<Server port="8005" shutdown="SHUTDOWN">
23. <!-- Security listener. Documentation at /docs/config/listeners.html
24. <Listener className="org.apache.catalina.security.SecurityListener" />
25. -->
26. <!--APR library loader. Documentation at /docs/apr.html -->
27. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
28. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
29. <Listener className="org.apache.catalina.core.JasperListener" />
30. <!-- Prevent memory leaks due to use of particular java/javax APIs-->
31. <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
32. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
33. <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
34.
35. <!-- Global JNDI resources
36. Documentation at /docs/jndi-resources-howto.html
37. -->
38. <GlobalNamingResources>
39. <!-- Editable user database that can also be used by
40. UserDatabaseRealm to authenticate users
41. -->
42. <Resource name="UserDatabase" auth="Container"
43. type="org.apache.catalina.UserDatabase"
44. description="User database that can be updated and saved"
45. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
46. pathname="conf/tomcat-users.xml" />
47. </GlobalNamingResources>
48.
49. <!-- A "Service" is a collection of one or more "Connectors" that share
50. a single "Container" Note: A "Service" is not itself a "Container",
51. so you may not define subcomponents such as "Valves" at this level.
52. Documentation at /docs/config/service.html
53. -->
54. <Service name="Catalina">
55.
56. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
57.
58. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
59. maxThreads="500" minSpareThreads="20" maxIdleTime="60000"/>
60.
61. <!-- A "Connector" represents an endpoint by which requests are received
62. and responses are returned. Documentation at :
63. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
64. Java AJP Connector: /docs/config/ajp.html
65. APR (HTTP/AJP) Connector: /docs/apr.html
66. Define a non-SSL HTTP/1.1 Connector on port 8080
67. -->
68. <!--
69. <Connector port="8080" protocol="HTTP/1.1"
70. connectionTimeout="20000"
71. redirectPort="8443" />
72. -->
73. <!-- A "Connector" using the shared thread pool-->
74.
75. <Connector executor="tomcatThreadPool"
76. port="8080" protocol="HTTP/1.1"
77. connectionTimeout="20000"
78. redirectPort="8443" URIEncoding="UTF-8" acceptCount="256"/>
79.
80. <!-- Define a SSL HTTP/1.1 Connector on port 8443
81. This connector uses the JSSE configuration, when using APR, the
82. connector should be using the OpenSSL style configuration
83. described in the APR documentation -->
84. <!--
85. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
86. maxThreads="150" scheme="https" secure="true"
87. clientAuth="false" sslProtocol="TLS" />
88. -->
89.
90. <!-- Define an AJP 1.3 Connector on port 8009 -->
91. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
92.
93.
94. <!-- An Engine represents the entry point (within Catalina) that processes
95. every request. The Engine implementation for Tomcat stand alone
96. analyzes the HTTP headers included with the request, and passes them
97. on to the appropriate Host (virtual host).
98. Documentation at /docs/config/engine.html -->
99.
100. <!-- You should set jvmRoute to support load-balancing via AJP ie : -->
101. <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat_B">
102.
103. <!-- <Engine name="Catalina" defaultHost="localhost"> -->
104.
105. <!--For clustering, please take a look at documentation at:
106. /docs/cluster-howto.html (simple how to)
107. /docs/config/cluster.html (reference documentation) -->
108. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
109. <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false"
110. notifyListenersOnReplication="true" />
111. <Channel className="org.apache.catalina.tribes.group.GroupChannel" >
112. <Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45564" frequency="500" dropTime = "3000"/>
113. <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4000" autoBind="100" selectorTimeout="5000" maxThreads = "6" />
114. <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter" >
115. <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
116. </Sender>
117. <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
118. <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
119. </Channel>
120. <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
121. <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
122. <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/"
123. watchDir="/tmp/war-listen/" watchEnabled = "false"/>
124. <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
125. <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
126. </Cluster>
127.
128. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
129. via a brute-force attack -->
130. <Realm className="org.apache.catalina.realm.LockOutRealm">
131. <!-- This Realm uses the UserDatabase configured in the global JNDI
132. resources under the key "UserDatabase". Any edits
133. that are performed against this UserDatabase are immediately
134. available for use by the Realm. -->
135. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
136. resourceName="UserDatabase"/>
137. </Realm>
138.
139. <Host name="localhost" appBase="webapps"
140. unpackWARs="true" autoDeploy="true">
141.
142. <!-- SingleSignOn valve, share authentication between web applications
143. Documentation at: /docs/config/valve.html -->
144. <!--
145. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
146. -->
147.
148. <!-- Access log processes all example.
149. Documentation at: /docs/config/valve.html
150. Note: The pattern used is equivalent to using pattern="common" -->
151. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
152. prefix="localhost_access_log." suffix=".txt"
153. pattern="%h %l %u %t "%r" %s %b" />
154.
155. </Host>
156. </Engine>
157. </Service>
158.</Server>
以上配置,基本与tomcat_A一样,只是Engine节点的jvmRoute属性为:tomcat_B。
· 好了,两个tomcat已经配置完成,如果你的两个tomcat在同一台机器上面,你得修改任意一个tomcat的所有端口号,以免端口冲突。
3.2配置apache httpd:
· 配置httpd.conf文件(usr/local/apache2/conf),我的配置内容为:
#
# This is the main Apache HTTP server configuration file. It containsthe
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2> for detailedinformation.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you areunsure
# consult the online docs. You have been warned.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or"drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not*begin
# with "/", the value of ServerRoot is prepended -- so'log/access_log'
# with ServerRoot set to '/www' will be interpreted by the
# server as '/www/log/access_log', where as '/log/access_log' will be
# interpreted as '/log/access_log'.
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk. If you wish to share the same ServerRoot formultiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/usr/local/apache2"
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 8000
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSOyou
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they areused.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule authn_default_module modules/mod_authn_default.so
#LoadModule authz_host_module modules/mod_authz_host.so
#LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
#LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_default_module modules/mod_authz_default.so
#LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule dbd_module modules/mod_dbd.so
LoadModule dumpio_module modules/mod_dumpio.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule include_module modules/mod_include.so
LoadModule filter_module modules/mod_filter.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule log_forensic_module modules/mod_log_forensic.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule ident_module modules/mod_ident.so
LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule info_module modules/mod_info.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule imagemap_module modules/mod_imagemap.so
LoadModule actions_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
</IfModule>
</IfModule>
# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition. These values also provide defaultsfor
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost>containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages,such
# as error documents. e.g. admin@your-domain.com
#
ServerAdmin you@example.com
#
# ServerName gives the name and port that the server uses to identifyitself.
# This can often be determined automatically, but we recommend youspecify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP addresshere.
#
#ServerName 192.168.0.27
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/usr/local/apache2/htdocs"
#
# Each directory to which Apache has access can be configured withrespect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive setof
# features.
#
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/usr/local/apache2/htdocs">
#
# Possible values for the Options directive are"None", "All",
# or any combination of:
# Indexes Includes FollowSymLinksSymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named*explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated andimportant. Please see
#http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in.htaccess files.
# It can be "All", "None", or anycombination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a<VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a<VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog "logs/error_log"
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
<IfModule log_config_module>
#
# The following directives define some format nicknames foruse with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b\"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b"common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and%O
LogFormat "%h %l %u %t \"%r\"%>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"combinedio
</IfModule>
#
# The location and format of the access logfile (CommonLogfile Format).
# If you do not define any access logfiles within a<VirtualHost>
# container, they will be logged here. Contrariwise,if you *do*
# define per-<VirtualHost> access logfiles,transactions will be
# logged therein and *not* in this file.
#
CustomLog "logs/access_log" common
#
# If you prefer a logfile with access, agent, and refererinformation
# (Combined Logfile Format) you can use the followingdirective.
#
#CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
#
# Redirect: Allows you to tell clients about documents thatused to
# exist in your server's namespace, but do not anymore. Theclient
# will make a new request for the document at its newlocation.
# Example:
# Redirect permanent /foo http://www.example.com/bar
#
# Alias: Maps web paths into filesystem paths and is usedto
# access content that does not live under theDocumentRoot.
# Example:
# Alias /webpath /full/filesystem/path
#
# If you include a trailing / on /webpath then the serverwill
# require it to be present in the URL. You will alsolikely
# need to provide a <Directory> section to allowaccess to
# the filesystem path.
#
# ScriptAlias: This controls which directories containserver scripts.
# ScriptAliases are essentially the same as Aliases, exceptthat
# documents in the target directory are treated asapplications and
# run by the server when requested rather than as documentssent to the
# client. The same rules about trailing "/"apply to ScriptAlias
# directives as to Alias.
#
ScriptAlias /cgi-bin/"/usr/local/apache2/cgi-bin/"
</IfModule>
<IfModule cgid_module>
#
# ScriptSock: On threaded servers, designate the path to theUNIX
# socket used to communicate with the CGI daemon ofmod_cgid.
#
#Scriptsock logs/cgisock
</IfModule>
#
# "/usr/local/apache2/cgi-bin" should be changed to whatever yourScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain"is
# a good value. If most of your content is binary, such asapplications
# or images, you may want to use "application/octet-stream" insteadto
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain
<IfModule mime_module>
#
# TypesConfig points to the file containing the list ofmappings from
# filename extension to MIME-type.
#
TypesConfig conf/mime.types
#
# AddType allows you to add to or override the MIMEconfiguration
# file specified in TypesConfig for specific filetypes.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsersuncompress
# information on the fly. Note: Not all browsers supportthis.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out,then you
# probably should define those extensions to indicate mediatypes:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
#
# AddHandler allows you to map certain file extensions to"handlers":
# actions unrelated to filetype. These can be either builtinto the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the"Options" directive.)
#
#AddHandler cgi-script .cgi
# For type maps (negotiated resources):
#AddHandler type-map var
#
# Filters allow you to process content before it is sent tothe client.
#
# To parse .shtml files for server-side includes(SSI):
# (You will also need to add "Includes" to the"Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
</IfModule>
#
# The mod_mime_magic module allows the server to use various hints fromthe
# contents of the file itself to determine its type. TheMIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile conf/magic
#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#
#
# MaxRanges: Maximum number of Ranges in a request before
# returning the entire resource, or one of the special
# values 'default', 'none' or 'unlimited'.
# Default setting is to accept 200 Ranges.
#MaxRanges unlimited
#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall is used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off
# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configurationof
# the server, or you may simply copy their contents here and change as
# necessary.
# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf
# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf
# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf
# Language settings
#Include conf/extra/httpd-languages.conf
# User home directories
#Include conf/extra/httpd-userdir.conf
# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf
# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf
# Various default settings
#Include conf/extra/httpd-default.conf
# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
# starting without SSL on platforms with no/dev/random equivalent
# but a statically compiled-inmod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
ProxyRequests Off
<Proxy balancer://myCluster/>
BalancerMember ajp://192.168.0.27:8009 loadfactor=1route=tomcat_A
BalancerMember ajp://192.168.0.30:8009 loadfactor=1route=tomcat_B
</Proxy>
以上配置中我修改了如下几点:
⑴#Listen 12.34.56.78:80
#Listen 80
Listen 8000
⑵# Example:
# LoadModule foo_module modules/mod_foo.so
#
这段配置下我注释了一些加载模块,请根据自己的选择注释一些无关的模块吧
⑶#
# ServerName gives the name and port that the server uses to identifyitself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP addresshere.
#
ServerName 192.168.0.27
我去掉这个注释,给它加上了本机IP地址,这是由于我的虚拟机IP地址设置有问题,如果你的正常可以不用修改
⑷# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Includeconf/extra/httpd-ssl.conf
去掉这两个注释,这个文件配置内容在下面有讲
⑸ProxyRequests Off
<Proxy balancer://myCluster/>
BalancerMember ajp://192.168.0.27:8009 loadfactor=1route=tomcat_A
BalancerMember ajp://192.168.0.30:8009 loadfactor=1route=tomcat_B
</Proxy>
在末尾加上这个,其中8009为tomcat的AJP端口号,请不要弄错8080那个类型的端口号了,tomcat_A、tomcat_B你应该知道修改成什么。
(6).配置httpd-vhosts.conf(/usr/local/apache2/conf/extra):
#
# Virtual Hosts
#
# If you want to maintain multipledomains/hostnames on your
# machine you can setup VirtualHost containersfor them. Most configurations
# use only name-based virtual hosts so theserver doesn't need to worry about
# IP addresses. This is indicated by theasterisks in the directives below.
#
# Please see the documentation at
#<URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setupvirtual hosts.
#
# You may use the command line option '-S' toverify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:8000
#
# VirtualHost example:
# Almost any Apache directive may go into aVirtualHost container.
# The first VirtualHost section is used for allrequests that do not
# match a ServerName or ServerAlias in any<VirtualHost> block.
#
<VirtualHost *:8000>
ServerAdminyou@example.com
ServerName192.168.0.27
ServerAlias192.168.0.27
ProxyPass /balancer://myCluster/ lbmethod=byrequests stickysession=JSESSIONIDnofailover=Off
ProxyPassReverse /balancer://myCluster/
ErrorLog"logs/dummy-host2.sm.com-error.log"
CustomLog"logs/dummy-host2.sm.com-access.log" common
</VirtualHost>
我去掉了原有的配置,加上我新的配置,其中stickysession=JSESSIONID为一种session共享机制,关于这种机制,你可以去网上搜索了解。
(7).按照以上配置你就已经完成:集群与session共享配置,如果你需要加上摘要认证,就看看下面配置。
(8).给apache进行摘要认证,其实只需简单的两步即可:
· 创建一个认证用户文件,进入apache2/bin,运行【./htdigest -c/usr/local/apache/conf/authuser/user.pwd "thinknet" thinknet】其中user.pwd表达认证用户文件、"thinknet"为AuthName、thinknet为用户名;Enter之后系统会提示你输入新密码与确认密码。
· 在conf/httpd.conf文件中新增这节点:
<Location/>
SetHandler hello-bdb
AuthType Digest
AuthName "thinknet"
AuthDigestProvider file
AuthUserFile /usr/local/apache2/conf/authuser/user.pwd
Require valid-user
</Location>
我是从这个网页得到的信息:http://www.wuseyun.com/htmldata/news/0/54154.html
(9).以上apache摘要认证就已经配置完成了,这时你访问你那两个tomcat下的资源时需要提供用户名与密码进行摘要认证;如果你不知道什么是摘要认证或是只想給tomcat加上摘要认证请看看我写的这篇文章:http://lsz1023-126-com.iteye.com/admin/blogs/2072066
(10).配置 ssl
下载ssl.ca-0.1.tar.gz 解压到 apachep安装目录的conf目录。 Tar –xfssl.ca-o.1.tar.gz
Cd ssl.ca-0.1
# ./new-root-ca.sh
No Root CA key round. Generating one
Generating RSA private key, 1024 bit longmodulus
...........................++++++
....++++++
e is 65537 (0x10001)
Enter pass phrase forca.key:
Verifying - Enter pass phrase for ca.key:
......
Self-sign the rootCA...
Enter pass phrase forca.key:
........
........
Country Name (2 letter code) [MY]:CN
State or Province Name (full name)[Perak]:ZheJiang
Locality Name (eg, city) [Sitiawan]:HangZhou
Organization Name (eg, company) [My DirectorySdn Bhd]:sc
Organizational Unit Name (eg, section)[Certification Services Division]:sc
Common Name (eg, MD Root CA) []:2
Email Address []:admin@admin.com
这样就生成了ca.key和ca.crt两个文件,接下来生成一个证书:
# ./new-server-cert.shserver
......
......
Country Name (2 letter code) [MY]:CN
State or Province Name (full name)[Perak]:ZheJiang
Locality Name (eg, city) [Sitiawan]:HangZhou
Organization Name (eg, company) [My DirectorySdn Bhd]:sc
Organizational Unit Name (eg, section) [SecureWeb Server]:sc
Common Name (eg, www.domain.com) []:192.168.0.27 (要和apache httpd.conf文件的ServerName 一致,或者域名)
Email Address []:admin@admin.com
这样就生成了server.csr和server.key这两个文件。
还需要签署一下才能使用的:
# ./sign-server-cert.sh server
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for./ca.key:
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'JiangSu'
localityName :PRINTABLE:'NanJing'
organizationName :PRINTABLE:'Wiscom System Co.,Ltd'
organizationalUnitName:PRINTABLE:'ACSTAR'
commonName :PRINTABLE:'acmail.wiscom.com.cn'
emailAddress :IA5STRING:'acmail@wiscom.com.cn'
Certificate is to be certified until Jul 1612:55:34 2005 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified,commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK
将ca.key和ca.crt,server.csr和server.key拷到apache2/conf目录下面。
或者将 apache2/conf/extra/httpd-ssl.conf下的路径改为证书文件的存放路径,如下所示。
SSLCertificateFile "/usr/local/apache2/conf/server.crt
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key
启动服务器,测试
$cd bin
$./apachectl start
浏览器中打入http://127.0.0.1/和https://127.0.0.1,如果看到同一个成功画面,说明apache+ssl配置成功.
给https配置tomcat集群
编辑apache2/conf/extra/httpd-ssl.conf 其中/usr/local/apache2为apache安装地址。
将 default_:443的基本参数。如果有就替换,之后的内容不要更改。
<VirtualHost _default_:443>
# General setup for the virtual host
ServerName 192.168.0.30
ServerAlias 192.168.0.30
ProxyRequests Off
ProxyPreserveHost on
ProxyPass / balancer://myCluster/ stickysession=JSESSIONID nofailover=Off
ProxyPassReverse / balancer://myCluster/
ErrorLog"/usr/local/apache2/logs/error_log"
TransferLog"/usr/local/apache2/logs/access_log"
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
tomcat集群参考 http://lsz1023-126-com.iteye.com/blog/2074165