mod_jk 订阅
mod_jk
信息
操作系统
跨平台
开发语言
JavaC/C++
开源协议
Apache
mod_jk
mod_jk 也叫 JK,这是一款 Apache /IIS 用来连接后台 Tomcat 的模块,支持集群和负载均衡。 JK 分为两个版本 1,x 和 2.x ,其中 2.x 并不是最新的版本,它是 JK 的另外一个分支,后不知何因没有继续开发,因此2.x 版本已经废弃了,请大家不要使用 2.x 的版本。
收起全文
精华内容
下载资源
问答
  • 压缩包中有mod_jk.so文件,同时附带apache官网下载链接。 内含windows32/64的各版本mod_jk.so文件,同时包含各版本iis文件。
  • mod_jk

    2012-03-11 13:50:55
    mod_jk至少需要两部分 mod_jk.xx,这是apache http服务器的模块,根据操作系统,可能是mod_jk.so,mod_jk.nlm,MOD_JK.SPVPGM。mod_jk安装到模块目录 workers.propertis一个用来描述tomcat所在主机,接受ajp协议...
    mod_jk至少需要两部分
    mod_jk.xx,这是apache http服务器的模块,根据操作系统,可能是mod_jk.so,mod_jk.nlm,MOD_JK.SPVPGM。mod_jk安装到模块目录

    workers.propertis一个用来描述tomcat所在主机,接受ajp协议的端口等信息的工作文件。
    展开全文
  • 首先虽然这个mod_jk已经过时,但还是放出来大家一起学习一下,文章主要分三部分内容: 1.第一部分:说明主要配置过程 2.第二部分:贴出我的httpd.conf文件 3.第三部分:对mod_jk代码讲解(来源百度) 第一部分:...

    首先虽然这个mod_jk已经过时,但还是放出来大家一起学习一下,文章主要分三部分内容:

    1.第一部分:说明主要配置过程

    2.第二部分:贴出我的httpd.conf文件

    3.第三部分:对mod_jk代码讲解(来源百度)

     

    第一部分:配置

    1.       准备环境:

    操作系统:windows7

    httpd-2.2.21-win32-x86-no_ssl.msi

    apache-tomcat-6.0.7

    apache-tomcat-5.0.7

    tomcat-connectors-1.2.32-windows-i386-httpd-2.2.x

    2.       下载APACHE

    这里下载的是APACHE2.2.21版本

    3.       下载JK(Tomcat Connector)

    Jk是apache和tomcat的连接器,也可以做负载均衡器,主要是apache通过jk找到tomcat。

    下载地址:http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/

    Jk的版本要与apache的版本对应如:mod_jk-1.2.32-httpd-2.2.x.zip其匹配的Apache为2.2.版本以上可用

    4.       下载TOMCAT

    apache-tomcat-6.0.7.rar

    apache-tomcat-6.0.7.rar

    5.       配置修改过程

    1)  Apache配置

    将Tomcat Connector文件mod_jk.so拷贝到Apache安装目录的modules目录下。

    在Apache安装目录下找到conf/httpd.conf文件,使用文本编辑器打开:

    伪静态修改

    将注释放开

    找到AllowOverride None 将其修改为 All 内容如下:

    [html] view plaincopyprint?

    1. <Directory />  
    2.   
    3.     Options FollowSymLinks  
    4.   
    5.     AllowOverride All  
    6.   
    7.     Order deny,allow  
    8.   
    9.     Deny from all  
    10.   
    11. </Directory>  

    Tomcat Connector关联项增加

            在LoadModules末尾处增加一下内容:

    [plain] view plaincopyprint?

    1. #加载mod_jk连接  
    2.   
    3. LoadModule jk_module modules/mod_jk.so  
    4.   
    5. ### 配置 mod_jk  
    6.   
    7. JkWorkersFile "conf\workers.properties" #加载集群中的workers  
    8.   
    9. #此处是指定分配给tomcat的请求 例如*.do *.jsp  
    10.   
    11. JkMount /*.jsp controller  
    12.   
    13. JkLogFile logs/mod_jk.log #指定jk的日志输出文件   
    14.   
    15. JkLogLevel warn #指定日志级别  
    16.   
    17.     找到IfModule dir_module 修改默认访问地址,需要根据具体项目实际情况填写,我这里使用的是index.jsp 修改如下:  
    18.   
    19. <IfModule dir_module>  
    20.   
    21. DirectoryIndex index.jsp  
    22.   
    23. </IfModule>  
    24.   
    25.     找到Virtual hosts 去掉虚拟主机注释  
    26.   
    27. # Virtual hosts  
    28.   
    29. #Include conf/extra/httpd-vhosts.conf 将 “#”去掉  
    30.   
    31. Include conf/extra/httpd-vhosts.conf  
    32.   
    33. 加载代理(暂时未去掉)  
    34.   
    35. #LoadModule proxy_module modules/mod_proxy.so  
    36.   
    37. #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so  
    38.   
    39. #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so  
    40.   
    41. #LoadModule proxy_connect_module modules/mod_proxy_connect.so  
    42.   
    43. #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so  

    2)  Tomcat Connector配置

    在Apache配置目录Apache2.2\conf创建workers.properties配置文件,该文件主要用于配置Apache与Tomcat的集成要用到的Tomcat实例和负载均衡分发控制器。

    Workers.properties文件放置一下内容;

    [plain] view plaincopyprint?

    1. #下面是分发控制器 注意不要放tomcat实例  
    2.   
    3. worker.list=lbcontroller  
    4.   
    5.    
    6.   
    7. #Tomcat1实例配置 这里要和Tomcat配置文件Service.xml的jvmRoute保持一致  
    8.   
    9. worker.test1.host=localhost  
    10.   
    11. worker.test1.port=8009  
    12.   
    13. worker.test1.type=ajp13  
    14.   
    15. #分发权重 值越大负载越大  
    16.   
    17. worker.tomcat1.lbfactor=1  
    18.   
    19.    
    20.   
    21. #Tomcat2实例配置  
    22.   
    23. worker.test2.host=localhost  
    24.   
    25. worker.test2.port=9009  
    26.   
    27. worker.test2.type=ajp13  
    28.   
    29. #分发权重 值越大负载越大  
    30.   
    31. worker.tomcat2.lbfactor=1  
    32.   
    33.    
    34.   
    35. #负载均衡分发控制器  
    36.   
    37. worker.lbcontroller.type=lb  
    38.   
    39. worker.lbcontroller.balance_workers=test1,test2  

    Tomcat配置文件Service.xml主要注意两个地方,一个是Engine节点需要增加节点标识jvmRoute,一个是将原本注释掉的Session复制节点改为有效。具体如下:

      

    [html] view plaincopyprint?

    1. <!--jvmRoute在各个Tomcat配置中不能重复且要与worker.properties文件中的名称一致-->  
    2.   
    3.     <Engine name="Catalina" defaultHost="localhost" jvmRoute="test1">  
    4.   
    5.    
    6.   
    7. <!--session复制内容-->  
    8.   
    9.        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"    
    10.   
    11.                  channelSendOptions="8">     
    12.   
    13.           <Manager className="org.apache.catalina.ha.session.DeltaManager"    
    14.   
    15.                    expireSessionsOnShutdown="false"    
    16.   
    17.                    notifyListenersOnReplication="true"/>     
    18.   
    19.     
    20.   
    21. <Channel className="org.apache.catalina.tribes.group.GroupChannel">     
    22.   
    23. <Membership className="org.apache.catalina.tribes.membership.McastService"    
    24.   
    25.                         address="228.0.0.4"    
    26.   
    27.                         port="45564"    
    28.   
    29.                         frequency="500"    
    30.   
    31.                         dropTime="3000"/>     
    32.   
    33. <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"    
    34.   
    35.                       address="auto"    
    36.   
    37.                       port="4000"    
    38.   
    39.                       autoBind="100"    
    40.   
    41.                       selectorTimeout="5000"    
    42.   
    43.                       maxThreads="6"/>     
    44.   
    45.             <!-- timeout="60000"-->     
    46.   
    47.             <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">     
    48.   
    49.               <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />     
    50.   
    51.             </Sender>     
    52.   
    53.             <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>     
    54.   
    55.             <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>     
    56.   
    57.             <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>     
    58.   
    59.           </Channel>     
    60.   
    61.           <!--过滤的文件-->  
    62.   
    63.           <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"  filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>     
    64.   
    65.           <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>     
    66.   
    67.     
    68.   
    69.           <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"    
    70.   
    71.                     tempDir="/tmp/war-temp/"    
    72.   
    73.                     deployDir="/tmp/war-deploy/"    
    74.   
    75.                     watchDir="/tmp/war-listen/"    
    76.   
    77.                     watchEnabled="false"/>     
    78.   
    79.           <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>     
    80.   
    81.           <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>     
    82.   
    83.         </Cluster>  
    84.   
    85.       <!--session复制内容-->  

                <!—Host节点增加一下内容表示站点根路径-->

    [html] view plaincopyprint?

    1. <Context path="/sc" docBase="." privileged="true"/>                                                           

    我们分别将两个Tomcat配置文件中的jvmRoute设置为tomcat1、tomcat2,Server节点 端口分别配置为8005和9005, Connector节点端口分别配置为8080和9090,AJPConnector端口分别配置为8009和9009,Connector端口配置参照单主机多站点场景。请注意两个Tomcat配置文件Host节点的域名配置必须一样,Server.xml中的jvmRoute名称必须和worker.properties中的tomcat实例名称一致,不然无法实现session_stricky。

     

    [html] view plaincopyprint?

    1. *****************************************************************************  
    2.   
    3.  如果需要实现session 复制 需要在Tomcat 下conf/web.xml 中加上<distributable/>  
    4.   
    5. <?xml version="1.0" encoding="ISO-8859-1"?>  
    6.   
    7. 省略N多代码。。。。。。  
    8.   
    9.     <welcome-file-list>  
    10.   
    11.         <welcome-file>index.html</welcome-file>  
    12.   
    13.         <welcome-file>index.htm</welcome-file>  
    14.   
    15.         <welcome-file>index.jsp</welcome-file>  
    16.   
    17.     </welcome-file-list>  
    18.   
    19. <distributable/>  
    20.   
    21. </web-app>  
    22.   
    23. *****************************************************************************  

     

    第二部分:httpd.conf文件

    [html] view plaincopyprint?

    1.   

    [html] view plaincopyprint?

    1. #  
    2. # This is the main Apache HTTP server configuration file.  It contains the  
    3. # configuration directives that give the server its instructions.  
    4. # See <URL:http://httpd.apache.org/docs/2.2> for detailed information.  
    5. # In particular, see   
    6. # <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>  
    7. # for a discussion of each configuration directive.  
    8. #  
    9. # Do NOT simply read the instructions in here without understanding  
    10. # what they do.  They're here only as hints or reminders.  If you are unsure  
    11. # consult the online docs. You have been warned.    
    12. #  
    13. # Configuration and logfile names: If the filenames you specify for many  
    14. # of the server's control files begin with "/" (or "drive:/" for Win32), the  
    15. # server will use that explicit path.  If the filenames do *not* begin  
    16. # with "/", the value of ServerRoot is prepended -- so "logs/foo.log"  
    17. # with ServerRoot set to "D:/Program Files/Apache Software Foundation/Apache2.2" will be interpreted by the  
    18. # server as "D:/Program Files/Apache Software Foundation/Apache2.2/logs/foo.log".  
    19. #  
    20. # NOTE: Where filenames are specified, you must use forward slashes  
    21. # instead of backslashes (e.g., "c:/apache" instead of "c:\apache").  
    22. # If a drive letter is omitted, the drive on which httpd.exe is located  
    23. # will be used by default.  It is recommended that you always supply  
    24. # an explicit drive letter in absolute paths to avoid confusion.  
    25.   
    26. #  
    27. # ServerRoot: The top of the directory tree under which the server's  
    28. # configuration, error, and log files are kept.  
    29. #  
    30. # Do not add a slash at the end of the directory path.  If you point  
    31. # ServerRoot at a non-local disk, be sure to point the LockFile directive  
    32. # at a local disk.  If you wish to share the same ServerRoot for multiple  
    33. # httpd daemons, you will need to change at least LockFile and PidFile.  
    34. #  
    35. ServerRoot "D:/Program Files/Apache Software Foundation/Apache2.2"  
    36.   
    37. #  
    38. # Listen: Allows you to bind Apache to specific IP addresses and/or  
    39. # ports, instead of the default. See also the <VirtualHost>  
    40. # directive.  
    41. #  
    42. # Change this to Listen on specific IP addresses as shown below to   
    43. # prevent Apache from glomming onto all bound IP addresses.  
    44. #  
    45. #Listen 12.34.56.78:80  
    46. Listen 8080  
    47.   
    48. #  
    49. # Dynamic Shared Object (DSO) Support  
    50. #  
    51. # To be able to use the functionality of a module which was built as a DSO you  
    52. # have to place corresponding `LoadModule' lines at this location so the  
    53. # directives contained in it are actually available _before_ they are used.  
    54. # Statically compiled modules (those listed by `httpd -l') do not need  
    55. # to be loaded here.  
    56. #  
    57. # Example:  
    58. # LoadModule foo_module modules/mod_foo.so  
    59. #  
    60. LoadModule actions_module modules/mod_actions.so  
    61. LoadModule alias_module modules/mod_alias.so  
    62. LoadModule asis_module modules/mod_asis.so  
    63. LoadModule auth_basic_module modules/mod_auth_basic.so  
    64. #LoadModule auth_digest_module modules/mod_auth_digest.so  
    65. #LoadModule authn_alias_module modules/mod_authn_alias.so  
    66. #LoadModule authn_anon_module modules/mod_authn_anon.so  
    67. #LoadModule authn_dbd_module modules/mod_authn_dbd.so  
    68. #LoadModule authn_dbm_module modules/mod_authn_dbm.so  
    69. LoadModule authn_default_module modules/mod_authn_default.so  
    70. LoadModule authn_file_module modules/mod_authn_file.so  
    71. #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so  
    72. #LoadModule authz_dbm_module modules/mod_authz_dbm.so  
    73. LoadModule authz_default_module modules/mod_authz_default.so  
    74. LoadModule authz_groupfile_module modules/mod_authz_groupfile.so  
    75. LoadModule authz_host_module modules/mod_authz_host.so  
    76. #LoadModule authz_owner_module modules/mod_authz_owner.so  
    77. LoadModule authz_user_module modules/mod_authz_user.so  
    78. LoadModule autoindex_module modules/mod_autoindex.so  
    79. #LoadModule cache_module modules/mod_cache.so  
    80. #LoadModule cern_meta_module modules/mod_cern_meta.so  
    81. LoadModule cgi_module modules/mod_cgi.so  
    82. #LoadModule charset_lite_module modules/mod_charset_lite.so  
    83. #LoadModule dav_module modules/mod_dav.so  
    84. #LoadModule dav_fs_module modules/mod_dav_fs.so  
    85. #LoadModule dav_lock_module modules/mod_dav_lock.so  
    86. #LoadModule dbd_module modules/mod_dbd.so  
    87. #LoadModule deflate_module modules/mod_deflate.so  
    88. LoadModule dir_module modules/mod_dir.so  
    89. #LoadModule disk_cache_module modules/mod_disk_cache.so  
    90. #LoadModule dumpio_module modules/mod_dumpio.so  
    91. LoadModule env_module modules/mod_env.so  
    92. #LoadModule expires_module modules/mod_expires.so  
    93. #LoadModule ext_filter_module modules/mod_ext_filter.so  
    94. #LoadModule file_cache_module modules/mod_file_cache.so  
    95. #LoadModule filter_module modules/mod_filter.so  
    96. #LoadModule headers_module modules/mod_headers.so  
    97. #LoadModule ident_module modules/mod_ident.so  
    98. #LoadModule imagemap_module modules/mod_imagemap.so  
    99. LoadModule include_module modules/mod_include.so  
    100. #LoadModule info_module modules/mod_info.so  
    101. LoadModule isapi_module modules/mod_isapi.so  
    102. #LoadModule ldap_module modules/mod_ldap.so  
    103. #LoadModule logio_module modules/mod_logio.so  
    104. LoadModule log_config_module modules/mod_log_config.so  
    105. #LoadModule log_forensic_module modules/mod_log_forensic.so  
    106. #LoadModule mem_cache_module modules/mod_mem_cache.so  
    107. LoadModule mime_module modules/mod_mime.so  
    108. #LoadModule mime_magic_module modules/mod_mime_magic.so  
    109. LoadModule negotiation_module modules/mod_negotiation.so  
    110. #LoadModule proxy_module modules/mod_proxy.so  
    111. #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so  
    112. #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so  
    113. #LoadModule proxy_connect_module modules/mod_proxy_connect.so  
    114. #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so  
    115. #LoadModule proxy_http_module modules/mod_proxy_http.so  
    116. #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so  
    117. #LoadModule reqtimeout_module modules/mod_reqtimeout.so  
    118. #url伪静态  
    119. LoadModule rewrite_module modules/mod_rewrite.so  
    120. LoadModule setenvif_module modules/mod_setenvif.so  
    121. #LoadModule speling_module modules/mod_speling.so  
    122. #LoadModule ssl_module modules/mod_ssl.so  
    123. #LoadModule status_module modules/mod_status.so  
    124. #LoadModule substitute_module modules/mod_substitute.so  
    125. #LoadModule unique_id_module modules/mod_unique_id.so  
    126. #LoadModule userdir_module modules/mod_userdir.so  
    127. #LoadModule usertrack_module modules/mod_usertrack.so  
    128. #LoadModule version_module modules/mod_version.so  
    129. #LoadModule vhost_alias_module modules/mod_vhost_alias.so  
    130.   
    131. #加载mod_jk连接  
    132. LoadModule jk_module modules/mod_jk.so  
    133. #加载集群中的workers  
    134. JkWorkersFile "conf/workers.properties"   
    135. #此处是指定分配给tomcat的请求 例如*.do *.jsp  
    136. JkMount /*.jsp lbcontroller  
    137. #指定jk的日志输出文件  
    138. JkLogFile "logs/mod_jk.log"  
    139. #指定日志级别  
    140. JkLogLevel warn   
    141.   
    142.   
    143.   
    144.   
    145. <IfModule !mpm_netware_module>  
    146. <IfModule !mpm_winnt_module>  
    147. #  
    148. # If you wish httpd to run as a different user or group, you must run  
    149. # httpd as root initially and it will switch.    
    150. #  
    151. # User/Group: The name (or #number) of the user/group to run httpd as.  
    152. # It is usually good practice to create a dedicated user and group for  
    153. # running httpd, as with most system services.  
    154. #  
    155. User daemon  
    156. Group daemon  
    157.   
    158. </IfModule>  
    159. </IfModule>  
    160.   
    161. # 'Main' server configuration  
    162. #  
    163. # The directives in this section set up the values used by the 'main'  
    164. # server, which responds to any requests that aren't handled by a  
    165. # <VirtualHost> definition.  These values also provide defaults for  
    166. # any <VirtualHost> containers you may define later in the file.  
    167. #  
    168. # All of these directives may appear inside <VirtualHost> containers,  
    169. # in which case these default settings will be overridden for the  
    170. # virtual host being defined.  
    171. #  
    172.   
    173. #  
    174. # ServerAdmin: Your address, where problems with the server should be  
    175. # e-mailed.  This address appears on some server-generated pages, such  
    176. # as error documents.  e.g. admin@your-domain.com  
    177. #  
    178. ServerAdmin localhost  
    179.   
    180. #  
    181. # ServerName gives the name and port that the server uses to identify itself.  
    182. # This can often be determined automatically, but we recommend you specify  
    183. # it explicitly to prevent problems during startup.  
    184. #  
    185. # If your host doesn't have a registered DNS name, enter its IP address here.  
    186. #  
    187. ServerName localhost:8080  
    188. #  
    189. # DocumentRoot: The directory out of which you will serve your  
    190. # documents. By default, all requests are taken from this directory, but  
    191. # symbolic links and aliases may be used to point to other locations.  
    192. #  
    193. DocumentRoot "D:/work/work_bz/test/WebRoot"  
    194. #  
    195. # Each directory to which Apache has access can be configured with respect  
    196. # to which services and features are allowed and/or disabled in that  
    197. # directory (and its subdirectories).   
    198. #  
    199. # First, we configure the "default" to be a very restrictive set of   
    200. # features.    
    201. #    默认为 AllowOverride None  
    202. <Directory />  
    203.     Options FollowSymLinks  
    204.     AllowOverride All  
    205.     #Order deny,allow  
    206.       #Deny from all  
    207.        Order allow,deny  
    208.     Allow from all  
    209.     Satisfy all  
    210. </Directory>  
    211.   
    212. #首次访问页面  
    213. <IfModule dir_module>  
    214.     DirectoryIndex index.jsp  
    215. </IfModule>  
    216.   
    217. #  
    218. # The following lines prevent .htaccess and .htpasswd files from being   
    219. # viewed by Web clients.   
    220. #  
    221. <FilesMatch "^\.ht">  
    222.     Order allow,deny  
    223.     Deny from all  
    224.     Satisfy All  
    225. </FilesMatch>  
    226.   
    227. #  
    228. # ErrorLog: The location of the error log file.  
    229. # If you do not specify an ErrorLog directive within a <VirtualHost>  
    230. # container, error messages relating to that virtual host will be  
    231. # logged here.  If you *do* define an error logfile for a <VirtualHost>  
    232. # container, that host's errors will be logged there and not here.  
    233. #  
    234. ErrorLog "logs/error.log"  
    235.   
    236. #  
    237. # LogLevel: Control the number of messages logged to the error_log.  
    238. # Possible values include: debug, info, notice, warn, error, crit,  
    239. # alert, emerg.  
    240. #  
    241. LogLevel warn  
    242.   
    243. <IfModule log_config_module>  
    244.     #  
    245.     # The following directives define some format nicknames for use with  
    246.     # a CustomLog directive (see below).  
    247.     #  
    248.     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  
    249.     LogFormat "%h %l %u %t \"%r\" %>s %b" common  
    250.   
    251.     <IfModule logio_module>  
    252.       # You need to enable mod_logio.c to use %I and %O  
    253.       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio  
    254.     </IfModule>  
    255.   
    256.     #  
    257.     # The location and format of the access logfile (Common Logfile Format).  
    258.     # If you do not define any access logfiles within a <VirtualHost>  
    259.     # container, they will be logged here.  Contrariwise, if you *do*  
    260.     # define per-<VirtualHost> access logfiles, transactions will be  
    261.     # logged therein and *not* in this file.  
    262.     #  
    263.     CustomLog "logs/access.log" common  
    264.   
    265.     #  
    266.     # If you prefer a logfile with access, agent, and referer information  
    267.     # (Combined Logfile Format) you can use the following directive.  
    268.     #  
    269.     #CustomLog "logs/access.log" combined  
    270. </IfModule>  
    271.   
    272. <IfModule alias_module>  
    273.     #  
    274.     # Redirect: Allows you to tell clients about documents that used to   
    275.     # exist in your server's namespace, but do not anymore. The client   
    276.     # will make a new request for the document at its new location.  
    277.     # Example:  
    278.     # Redirect permanent /foo http://192.168.12.242/bar  
    279.   
    280.     #  
    281.     # Alias: Maps web paths into filesystem paths and is used to  
    282.     # access content that does not live under the DocumentRoot.  
    283.     # Example:  
    284.     # Alias /webpath /full/filesystem/path  
    285.     #  
    286.     # If you include a trailing / on /webpath then the server will  
    287.     # require it to be present in the URL.  You will also likely  
    288.     # need to provide a <Directory> section to allow access to  
    289.     # the filesystem path.  
    290.   
    291.     #  
    292.     # ScriptAlias: This controls which directories contain server scripts.   
    293.     # ScriptAliases are essentially the same as Aliases, except that  
    294.     # documents in the target directory are treated as applications and  
    295.     # run by the server when requested rather than as documents sent to the  
    296.     # client.  The same rules about trailing "/" apply to ScriptAlias  
    297.     # directives as to Alias.  
    298.     #  
    299.     ScriptAlias /cgi-bin/ "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"  
    300.   
    301. </IfModule>  
    302.   
    303. <IfModule cgid_module>  
    304.     #  
    305.     # ScriptSock: On threaded servers, designate the path to the UNIX  
    306.     # socket used to communicate with the CGI daemon of mod_cgid.  
    307.     #  
    308.     #Scriptsock logs/cgisock  
    309. </IfModule>  
    310.   
    311. #  
    312. # "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased  
    313. # CGI directory exists, if you have that configured.  
    314. #  
    315. <Directory "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">  
    316.     AllowOverride None  
    317.     Options None  
    318.     Order allow,deny  
    319.     Allow from all  
    320. </Directory>  
    321.   
    322. #  
    323. # DefaultType: the default MIME type the server will use for a document  
    324. # if it cannot otherwise determine one, such as from filename extensions.  
    325. # If your server contains mostly text or HTML documents, "text/plain" is  
    326. # a good value.  If most of your content is binary, such as applications  
    327. # or images, you may want to use "application/octet-stream" instead to  
    328. # keep browsers from trying to display binary files as though they are  
    329. # text.  
    330. #  
    331. DefaultType text/plain  
    332.   
    333. <IfModule mime_module>  
    334.     #  
    335.     # TypesConfig points to the file containing the list of mappings from  
    336.     # filename extension to MIME-type.  
    337.     #  
    338.     TypesConfig conf/mime.types  
    339.   
    340.     #  
    341.     # AddType allows you to add to or override the MIME configuration  
    342.     # file specified in TypesConfig for specific file types.  
    343.     #  
    344.     #AddType application/x-gzip .tgz  
    345.     #  
    346.     # AddEncoding allows you to have certain browsers uncompress  
    347.     # information on the fly. Note: Not all browsers support this.  
    348.     #  
    349.     #AddEncoding x-compress .Z  
    350.     #AddEncoding x-gzip .gz .tgz  
    351.     #  
    352.     # If the AddEncoding directives above are commented-out, then you  
    353.     # probably should define those extensions to indicate media types:  
    354.     #  
    355.     AddType application/x-compress .Z  
    356.     AddType application/x-gzip .gz .tgz  
    357.   
    358.     #  
    359.     # AddHandler allows you to map certain file extensions to "handlers":  
    360.     # actions unrelated to filetype. These can be either built into the server  
    361.     # or added with the Action directive (see below)  
    362.     #  
    363.     # To use CGI scripts outside of ScriptAliased directories:  
    364.     # (You will also need to add "ExecCGI" to the "Options" directive.)  
    365.     #  
    366.     #AddHandler cgi-script .cgi  
    367.   
    368.     # For type maps (negotiated resources):  
    369.     #AddHandler type-map var  
    370.   
    371.     #  
    372.     # Filters allow you to process content before it is sent to the client.  
    373.     #  

    展开全文
  • CentOS 7安裝Apache编译mod_jk 2.安裝编译工具 yum install -y gcc* 3.下載tomcat-connector wget http://mirrors.shuosc.org/apache/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.42-src.tar.gz...
    CentOS 7安裝Apache编译mod_jk

    2.安裝编译工具
    yum install -y gcc*

    3.下載tomcat-connector
    wget http://mirrors.shuosc.org/apache/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.42-src.tar.gz


    4.解压
    tar zxf tomcat-connectors-1.2.40-src.tar.gz


    5.进入到native 目录
    cd tomcat-connectors-1.2.40-src/native

    // 编译配置
    ./buildconf.sh

    // 依赖    安装依赖  重新编译
     yum install autoconf
     yum -y install libtool
     ./buildconf.sh

    7.编译mod_jk    //将文件 mod_jk.so  释放到哪里   放到 apache httpd 的
    ./configure --with-apxs=/web/httpd2.2.4/bin/apxs           说明: ./configure --with-apxs=apxs的路徑   (httpd/bin)

    //编译 安装
    make && make install
    展开全文
  • 首先虽然这个mod_jk已经过时,但还是放出来大家一起学习一下,文章主要分三部分内容: 1.第一部分:说明主要配置过程 2.第二部分:贴出我的httpd.conf文件 3.第三部分:对mod_jk代码讲解(来源百度)   ...

     首先虽然这个mod_jk已经过时,但还是放出来大家一起学习一下,文章主要分三部分内容:

    1.第一部分:说明主要配置过程

    2.第二部分:贴出我的httpd.conf文件

    3.第三部分:对mod_jk代码讲解(来源百度)

     

    第一部分:配置

    1.       准备环境:

    操作系统:windows7

    httpd-2.2.21-win32-x86-no_ssl.msi

    apache-tomcat-6.0.7

    apache-tomcat-5.0.7

    tomcat-connectors-1.2.32-windows-i386-httpd-2.2.x

    jdk1.5

    2.       下载APACHE

    这里下载的是APACHE2.2.21版本

    3.       下载JK(Tomcat
    Connector)

    Jk是apache和tomcat的连接器,也可以做负载均衡器,主要是apache通过jk找到tomcat。

    下载地址:http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/Jk的版本要与apache的版本对应如:mod_jk-1.2.32-httpd-2.2.x.zip其匹配的Apache为2.2.版本以上可用

    4.       下载TOMCAT

    apache-tomcat-6.0.7.rar

    5.       配置修改过程

    1)  Apache配置

    将Tomcat Connector文件mod_jk.so拷贝到Apache安装目录的modules目录下。

    在Apache安装目录下找到conf/httpd.conf文件,使用文本编辑器打开:

    伪静态修改

    将注释放开

    找到AllowOverride None 将其修改为 All 内容如下:

    <Directory />
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
    </Directory>

    Tomcat Connector关联项增加

           
    在LoadModules末尾处增加一下内容:

    #加载mod_jk连接
    LoadModule jk_module modules/mod_jk.so
    ### 配置 mod_jk
    JkWorkersFile "confworkers.properties" #加载集群中的workers
    #此处是指定分配给tomcat的请求 例如*.do *.jsp
    JkMount /*.jsp controller
    JkLogFile logs/mod_jk.log #指定jk的日志输出文件
    JkLogLevel warn #指定日志级别
        找到IfModule dir_module 修改默认访问地址,需要根据具体项目实际情况填写,我这里使用的是index.jsp 修改如下:
    <IfModule dir_module>
    DirectoryIndex index.jsp
    </IfModule>
        找到Virtual hosts 去掉虚拟主机注释
    # Virtual hosts
    #Include conf/extra/httpd-vhosts.conf 将 “#”去掉
    Include conf/extra/httpd-vhosts.conf
    加载代理(暂时未去掉)
    #LoadModule proxy_module modules/mod_proxy.so
    #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    #LoadModule proxy_connect_module modules/mod_proxy_connect.so
    #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

    2)  Tomcat Connector配置

    在Apache配置目录Apache2.2conf创建workers.properties配置文件,该文件主要用于配置Apache与Tomcat的集成要用到的Tomcat实例和负载均衡分发控制器。

    Workers.properties文件放置一下内容;

    #下面是分发控制器 注意不要放tomcat实例
    worker.list=lbcontroller
    #Tomcat1实例配置 这里要和Tomcat配置文件Service.xml的jvmRoute保持一致
    worker.test1.host=localhost
    worker.test1.port=8009
    worker.test1.type=ajp13
    #分发权重 值越大负载越大
    worker.tomcat1.lbfactor=1
    #Tomcat2实例配置
    worker.test2.host=localhost
    worker.test2.port=9009
    worker.test2.type=ajp13
    #分发权重 值越大负载越大
    worker.tomcat2.lbfactor=1
    #负载均衡分发控制器
    worker.lbcontroller.type=lb
    worker.lbcontroller.balance_workers=test1,test2
    Tomcat配置文件Service.xml主要注意两个地方,一个是Engine节点需要增加节点标识jvmRoute,一个是将原本注释掉的Session复制节点改为有效。具体如下:

      

    <!--jvmRoute在各个Tomcat配置中不能重复且要与worker.properties文件中的名称一致-->
        <Engine name="Catalina" defaultHost="localhost" jvmRoute="test1">
    <!--session复制内容-->
           <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                     channelSendOptions="8">
              <Manager className="org.apache.catalina.ha.session.DeltaManager"
                       expireSessionsOnShutdown="false"
                       notifyListenersOnReplication="true"/>
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
    <Membership className="org.apache.catalina.tribes.membership.McastService"
                            address="228.0.0.4"
                            port="45564"
                            frequency="500"
                            dropTime="3000"/>
    <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                          address="auto"
                          port="4000"
                          autoBind="100"
                          selectorTimeout="5000"
                          maxThreads="6"/>
                <!-- timeout="60000"-->
                <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                  <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
                </Sender>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
              </Channel>
              <!--过滤的文件-->
              <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"  filter=".*.gif;.*.js;.*.jpg;.*.png;.*.htm;.*.html;.*.css;.*.txt;"/>
              <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
              <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                        tempDir="/tmp/war-temp/"
                        deployDir="/tmp/war-deploy/"
                        watchDir="/tmp/war-listen/"
                        watchEnabled="false"/>
              <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
              <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
            </Cluster>
          <!--session复制内容-->

               
    <!—Host节点增加一下内容表示站点根路径-->

    <Context path="/sc" docBase="." privileged="true"/>

    我们分别将两个Tomcat配置文件中的jvmRoute设置为tomcat1、tomcat2,Server节点
    端口分别配置为8005和9005,
    Connector节点端口分别配置为8080和9090,AJPConnector端口分别配置为8009和9009,Connector端口配置参照单主机多站点场景。请注意两个Tomcat配置文件Host节点的域名配置必须一样,Server.xml中的jvmRoute名称必须和worker.properties中的tomcat实例名称一致,不然无法实现session_stricky。

     

    *****************************************************************************
     如果需要实现session 复制 需要在Tomcat 下conf/web.xml 中加上<distributable/>
    <?xml version="1.0" encoding="ISO-8859-1"?>
    省略N多代码。。。。。。
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
            <welcome-file>index.htm</welcome-file>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    <distributable/>
    </web-app>
    *****************************************************************************
    第二部分:httpd.conf文件#
    # This is the main Apache HTTP server configuration file. It contains the
    # configuration directives that give the server its instructions.
    # See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
    # 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 are unsure
    # 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 "logs/foo.log"
    # with ServerRoot set to "D:/Program Files/Apache Software Foundation/Apache2.2" will be interpreted by the
    # server as "D:/Program Files/Apache Software Foundation/Apache2.2/logs/foo.log".
    #
    # NOTE: Where filenames are specified, you must use forward slashes
    # instead of backslashes (e.g., "c:/apache" instead of "c:apache").
    # If a drive letter is omitted, the drive on which httpd.exe is located
    # will be used by default. It is recommended that you always supply
    # an explicit drive letter in absolute paths to avoid confusion.
    #
    # 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 for multiple
    # httpd daemons, you will need to change at least LockFile and PidFile.
    #
    ServerRoot "D:/Program Files/Apache Software Foundation/Apache2.2"
    #
    # 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 8080
    #
    # Dynamic Shared Object (DSO) Support
    #
    # To be able to use the functionality of a module which was built as a DSO you
    # have to place corresponding `LoadModule' lines at this location so the
    # directives contained in it are actually available _before_ they are used.
    # Statically compiled modules (those listed by `httpd -l') do not need
    # to be loaded here.
    #
    # Example:
    # LoadModule foo_module modules/mod_foo.so
    #
    LoadModule actions_module modules/mod_actions.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule asis_module modules/mod_asis.so
    LoadModule auth_basic_module modules/mod_auth_basic.so
    #LoadModule auth_digest_module modules/mod_auth_digest.so
    #LoadModule authn_alias_module modules/mod_authn_alias.so
    #LoadModule authn_anon_module modules/mod_authn_anon.so
    #LoadModule authn_dbd_module modules/mod_authn_dbd.so
    #LoadModule authn_dbm_module modules/mod_authn_dbm.so
    LoadModule authn_default_module modules/mod_authn_default.so
    LoadModule authn_file_module modules/mod_authn_file.so
    #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
    #LoadModule authz_dbm_module modules/mod_authz_dbm.so
    LoadModule authz_default_module modules/mod_authz_default.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_host_module modules/mod_authz_host.so
    #LoadModule authz_owner_module modules/mod_authz_owner.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule autoindex_module modules/mod_autoindex.so
    #LoadModule cache_module modules/mod_cache.so
    #LoadModule cern_meta_module modules/mod_cern_meta.so
    LoadModule cgi_module modules/mod_cgi.so
    #LoadModule charset_lite_module modules/mod_charset_lite.so
    #LoadModule dav_module modules/mod_dav.so
    #LoadModule dav_fs_module modules/mod_dav_fs.so
    #LoadModule dav_lock_module modules/mod_dav_lock.so
    #LoadModule dbd_module modules/mod_dbd.so
    #LoadModule deflate_module modules/mod_deflate.so
    LoadModule dir_module modules/mod_dir.so
    #LoadModule disk_cache_module modules/mod_disk_cache.so
    #LoadModule dumpio_module modules/mod_dumpio.so
    LoadModule env_module modules/mod_env.so
    #LoadModule expires_module modules/mod_expires.so
    #LoadModule ext_filter_module modules/mod_ext_filter.so
    #LoadModule file_cache_module modules/mod_file_cache.so
    #LoadModule filter_module modules/mod_filter.so
    #LoadModule headers_module modules/mod_headers.so
    #LoadModule ident_module modules/mod_ident.so
    #LoadModule imagemap_module modules/mod_imagemap.so
    LoadModule include_module modules/mod_include.so
    #LoadModule info_module modules/mod_info.so
    LoadModule isapi_module modules/mod_isapi.so
    #LoadModule ldap_module modules/mod_ldap.so
    #LoadModule logio_module modules/mod_logio.so
    LoadModule log_config_module modules/mod_log_config.so
    #LoadModule log_forensic_module modules/mod_log_forensic.so
    #LoadModule mem_cache_module modules/mod_mem_cache.so
    LoadModule mime_module modules/mod_mime.so
    #LoadModule mime_magic_module modules/mod_mime_magic.so
    LoadModule negotiation_module modules/mod_negotiation.so
    #LoadModule proxy_module modules/mod_proxy.so
    #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    #LoadModule proxy_balancer_module modules/mod_proxy_balancer.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 reqtimeout_module modules/mod_reqtimeout.so
    #url伪静态
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule setenvif_module modules/mod_setenvif.so
    #LoadModule speling_module modules/mod_speling.so
    #LoadModule ssl_module modules/mod_ssl.so
    #LoadModule status_module modules/mod_status.so
    #LoadModule substitute_module modules/mod_substitute.so
    #LoadModule unique_id_module modules/mod_unique_id.so
    #LoadModule userdir_module modules/mod_userdir.so
    #LoadModule usertrack_module modules/mod_usertrack.so
    #LoadModule version_module modules/mod_version.so
    #LoadModule vhost_alias_module modules/mod_vhost_alias.so
    #加载mod_jk连接
    LoadModule jk_module modules/mod_jk.so
    #加载集群中的workers
    JkWorkersFile "conf/workers.properties"
    #此处是指定分配给tomcat的请求 例如*.do *.jsp
    JkMount /*.jsp lbcontroller
    #指定jk的日志输出文件
    JkLogFile "logs/mod_jk.log"
    #指定日志级别
    JkLogLevel warn
    <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 defaults for
    # 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 localhost
    #
    # ServerName gives the name and port that the server uses to identify itself.
    # 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 address here.
    #
    ServerName localhost:8080
    #
    # 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 "D:/work/work_bz/test/WebRoot"
    #
    # Each directory to which Apache has access can be configured with respect
    # 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 set of
    # features.
    # 默认为 AllowOverride None
    <Directory />
    Options FollowSymLinks
    AllowOverride All
    #Order deny,allow
    #Deny from all
    Order allow,deny
    Allow from all
    Satisfy all
    </Directory>
    #首次访问页面
    <IfModule dir_module>
    DirectoryIndex index.jsp
    </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 for use 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 (Common Logfile 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 referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access.log" combined
    </IfModule>
    <IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to
    # exist in your server's namespace, but do not anymore. The client
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://192.168.12.242/bar
    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL. You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.
    #
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client. The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
    </IfModule>
    <IfModule cgid_module>
    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    #Scriptsock logs/cgisock
    </IfModule>
    #
    # "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
    <Directory "D:/Program Files/Apache Software Foundation/Apache2.2/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 as applications
    # or images, you may want to use "application/octet-stream" instead to
    # 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 of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types
    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #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 media types:
    #
    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 built into 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 to the 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 from the
    # contents of the file itself to determine its type. The MIMEMagicFile
    # 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://192.168.12.242/subscription_info.html
    #
    #
    # MaxRanges: Maximum number of Ranges in a request before
    # returning the entire resource, or 0 for unlimited
    # Default setting is to accept 200 Ranges
    #MaxRanges 0
    #
    # 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 configuration of
    # 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-in mod_ssl.
    #
    <IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
    </IfModule>
    第三部分:mod_jk代码讲解

    mod_jk 分析
    1 mod_jk模块的总体功能
    由于tomcat的HTTP处理部分都由Java所写(5.5.12版本以后出现了native库,用以
    提高其I/O和SSL的性能[1]),在高并发的情况下负载较高。而apache对于静态文件的处
    理能力比tomcat强,所以tomcat开发组开发了与apache结合使用的mod_jk模块。该协议
    由apache作请求代理,将HTTP协议的请求转化为AJP协议包,并传给后端的
    tomcat。mod_jk和apache现在普遍使用AJP1.3协议[2]。它是一个二进制格式的协议,比
    字符格式的HTTP协议解析速度要快。
    除了性能的提升,mod_jk另外的一个作用可以实现apache与tomcat一对多的对应,
    使后端tomcat负载均衡。mod_jk也提供apache与tomcat链接情况的监控。
    mod_jk模块的典型工作流程是这样的:一个HTTP请求过来,mod_jk模块根据其URI选
    择合适的worker来进行处理。如果是lb_worker(负载均衡的worker),就再根据各种条
    件选择后台合适的ajp_worker(处理AJP协议的worker)。ajp_worker将HTTP协议的包,
    组装成AJP协议格式的包,然后选取一条空闲的链接,发送给后台的tomcat服务器。等到
    后台将数据发送过来时,接收并解析AJP协议,重新组装成HTTP协议,然后把结果发送给
    客户端。
    2 mod_jk模块的框架
    2.1 线程
    从宏观上来讲,mod_jk由一个watchdog线程和一组worker线程(进程)组成。
    watchdog线程是在apache内部新创建的线程,它是一个维护线程。每隔
    JkWatchdogInterval的时间(当然,所有worker线程也有一个统一的worker.maintain 时
    间,JkWatchdogInterval应该至少大于worker.maintain),它会扫描所有worker线程。
    watchdog线程会检查每个worker线程的空闲链接、负载情况、与后端的链接情况,并使共
    享内存同步。worker线程是就是一些ajp13,ajp14,jni,lb或status类型的线程,负责
    所有实际的工作。
    在mod_jk中,线程内(外)的同步均是通过线程锁(pthread_mutex_lock)来实现的。
    而进程之间的全局同步,是用文件记录锁(flock或fcntl)来实现。进程间的数据共享是
    用这样做的:进程启动时,创建一个JkShmSize 大小的文件,然后mmap到内存,由于各进
    程mmap到内存的是相同的镜像,所以可以实现数据的共享,但是写入共享内存时,要做好
    互斥。
    由于apache的基本处理方式(prefork和worker模式)就是一个线程/进程负责一个
    连接,所以mod_jk各线程中对于网络IO处理都是阻塞的。
    2.2 worker对象
    从具体的worker对象的角度来讲,mod_jk由ajp_worker、jni_worker、lb_worker和
    status_worker组成。这些对象参考了设计模式中factory的模型。每类worker都有生产
    workers的factory。
    在mod_jk中,其中的worker主要在worker.list中列出。其中,lb_worker可以含有
    balance_workers,以lb_sub_worker的形式存储于lb_worker中。lb_sub_worker可以是各
    种类型的ajp_worker。所以真正工作的ajp_worker既可以“单干”,也可以由lb_worker
    来分配任务。这主要取决于URI到底映射到哪个worker上以及该worker是否在
    worker.list配置。
    lb_worker,lb_sub_worker和ajp_worker一些配置信息都位于其结构体中,而状态信
    息或在运行中可变的参数则位于共享内存中的对应结构体中,当然也并不绝对,有些参数是
    冗余的。
    从正在运行的某个线程的角度上来讲,ajp_worker就是对应了一个线程。
    3 从HTTP到AJP的处理流程
    由于mod_jk模块是apache的处理模块,本节主要是讲述mod_jk模块从客户端到后端
    服务器的处理流程。中间会涉及一些apache模块的一些结构。
    3.1 mod_jk模块在apache中的定义
    3.1.1 mod_jk定义
    /* 这是jk模块的主要定义结构体*/
    module AP_MODULE_DECLARE_DATA jk_module = {
    STANDARD20_MODULE_STUFF,
    NULL, /* dir config creater */
    NULL, /* dir merger --- default is to override */
    create_jk_config, /*创建 jk模块的配置结构体*/
    merge_jk_config, /* 初始化及合并 jk模块的配置结构体*/
    jk_cmds, /* 所有在apahce中的命令及操作函数 */
    jk_register_hooks /* 具体的操作函数处理钩子 */
    };
    3.1.2 mod_jk模块的主要处理函数
    /* mod_jk将各处理函数挂到相应的钩子上,钩子实际上就是一些函数指针。针对某个HTTP
    请求,这些函数会自上而下执行。*/
    static void jk_register_hooks(apr_pool_t * p)
    {
    /* 该函数在apache读入配置后运行,用以初始化全局互斥锁,jk日志,全局变量的初
    始化,以及读入 workers.properties、uriworkermap.properties文件,初始化各worker
    的属性,建立worker名称到worker结构体的映射,uri到worker的映射*/
    ap_hook_post_config(jk_post_config, NULL, NULL,
    APR_HOOK_MIDDLE);
    /*该函数在apache主进程fork工作子进程后做的初始化工作,主要包括初始化进程内
    互斥锁,开启维护线程,读入共享内存*/
    ap_hook_child_init(jk_child_init, NULL, NULL, APR_HOOK_MIDDLE);
    /* 将mod_jk的URI到真实URI,然后URI到worker的映射翻译过程,用以找到该URI
    相应的worker_name */
    ap_hook_translate_name(jk_translate, NULL, NULL,
    APR_HOOK_MIDDLE);
    #if (MODULE_MAGIC_NUMBER_MAJOR > 20010808)
    /* 绑定那些alias_dir的URI到mod_jk的配置,并找到相应worker_name */
    ap_hook_map_to_storage(jk_map_to_storage, NULL, NULL,
    APR_HOOK_MIDDLE);
    /* 这是mod_jk的主要处理函数 */
    ap_hook_handler(jk_handler, NULL, NULL, APR_HOOK_MIDDLE);
    #endif
    }
    3.2 jk_handler函数
    jk_handler函数是mod_jk的主要处理函数,它负责将HTTP请求从apache发到tomcat,
    再从tomcat接受数据,并返回给客户。
    它的处理过程如下:
    1. 根据前面得到的worker_name,找到相应的jk_worker(其结构体见4.4)。
    2. 初始化服务结构体jk_ws_service,主要是针对HTTP服务端的一些设置及函数(服务
    的结构体见4.5),与AJP协议关系不大。
    3. 调用jk_worker的get_endpoint函数,获取具体的jk_endpoint结构体(函数见
    3.3.1和3.4.1,jk_endpoint的结构体定义见4.4)。
    4. 调用上述jk_endpoint的service函数。
    5. 调用上述jk_endpoint的done函数,结束与tomcat的AJP连接。
    6. 根据函数的结果处理各种状态。
    7. 释放资源。
    3.3 lb_worker的处理函数
    3.3.1 lb_worker的get_endpoint
    初始化lb_worker的endpoint结构体,挂上其service及done函数。
    3.3.2 lb_worker的service函数
    它的处理过程如下:
    1. 获取共享内存中记录的worker状态。
    2. 如果需要绑定sessionID,获取sessionID。
    3. 调用get_most_suitable_worker函数,获取相应的lb_sub_worker(也即
    ajp_worker)。
    4. 调用ajp_worker的get_endpoint函数。
    5. 调用上述endpoint的service函数。
    6. 调用上述endpoint的done函数。
    7. 根据service的返回结果,更新各种记录状态。
    3.3.3 get_most_suitable_worker函数
    它的处理过程如下:
    1. 如果需要绑定sessionID,就根据sessionID找到工作正常的最佳worker。
    2. 如果找不到,则调用find_best_worker函数。其处理过程如下:
    i. 又调用find_best_byvalue函数。其处理过程如下:按照Round Robin的方式在
    本lb_worker中找到第一个不在错误状态、也没有停止、没有disabled 、也不
    busy的lb_sub_worker。
    ii.如果find_best_byvalue返回错误,说明本lb_worker的lb_sub_worker都处于
    非正常工作状态,需要调用find_failover_worker函数,通过
    redirect、route、domain指令来进行查找[3]。
    3.4 ajp_worker的处理函数
    3.4.1 ajp_worker的get_endpoint函数
    它的主要功能是:找到与后端tomcat的一个空闲连接。
    3.4.2 ajp_worker的ajp_service函数
    该函数主要分为 ajp_send_request和and ajp_get_reply两个函数。
    它的处理过程如下:
    1. 获取共享内存中的状态。
    2. 分配AJP请求包、恢复包、POST包的内存。
    3. 调用ajp_marshal_into_msgb函数,将HTTP请求包转化为AJP包。
    4. 将当前ajp_worker的状态更新。
    5. 调用ajp_send_request函数。
    6. 如果发送成功,调用ajp_get_reply函数,等待并接受AJP包。
    7. 如果成功,更新当前状态。
    3.4.2 ajp_worker的ajp_send_request函数
    它的处理过程如下:
    1. 调用jk_is_socket_connected函数,检查即将发送的socket是否有效。它的检查过
    程是运用select函数,等1微妙,如果成功返回说明,该socket的文件描述符至少
    在内核中还有效。
    2. 如果上一次发送超时,则调用ajp_handle_cping_cpong函数来判断后端连接是否有
    效。该函数主要是发出了一个AJP13_CPING_REQUEST类型的AJP包,如果tomcat收
    到,应返回一个AJP13_CPONG_REPLY的包。
    3. 如果上述的测试都成功,调用ajp_connection_tcp_send_message,发送AJP包。
    3.4.3 ajp_worker的ajp_get_reply函数
    它的处理过程如下:
    1. 调用jk_is_input_event,用select等待接受数据,直到socket有接受数据。
    2. 调用ajp_connection_tcp_get_message,接受AJP包,并检查协议头。
    3. 调用ajp_process_callback,对该AJP包进行解析处理。其处理过程如下:
    i. 如果是JK_AJP13_SEND_HEADERS包,将其解包成HTTP包头。如果没有错误,就调
    用jk_ws_service->start_response()函数发送HTTP回复的head。返回
    JK_AJP13_SEND_HEADERS。
    ii.如果是JK_AJP13_SEND_BODY_CHUNK包,调用jk_ws_service->write发送HTTP回
    复的body。返回JK_AJP13_NO_RESPONSE。
    iii.如果是JK_AJP13_GET_BODY_CHUNK包,说明还有数据要发送到tomcat,调用
    ajp_read_into_msg_buff,继续发送数据。返回JK_AJP13_HAS_RESPONSE。
    iv.如果是JK_AJP13_END_RESPONSE包,就说明tomcat的回复已经完成。返回
    JK_AJP13_END_RESPONSE。
    3.5 jk_ws_service的一些处理函数
    3.5.1 jk_ws_service 的 ws_start_response函数
    该函数主要是构建HTTP回复包的头部。
    3.5.2 jk_ws_service 的 ws_write函数
    调用 apache的ap_rwrite函数,发送整个HTTP包。
    3.5.3 jk_ws_service 的 ws_read函数
    调用apache的ap_get_client_block读入全部的request body数据。
    4 mod_jk的主要数据结构
    4.1 lb_worker
    lb_worker是负载均衡worker。主要负责调配其名下的一些lb_sub_worker 。

    dist/common/jk_lb_worker.h
    struct lb_worker
    {
    /* jk模块通用worker结构体。包含一些回调函数,不同的worker有不同的函数实现
    */
    jk_worker_t worker;
    /* Shared memory worker data */
    jk_shm_lb_worker_t *s;
    char name[JK_SHM_STR_SIZ+1];
    /* Sequence counter starting at 0 and increasing
    * every time we change the config
    */
    volatile unsigned int sequence;
    jk_pool_t p;
    jk_pool_atom_t buf[TINY_POOL_SIZE];
    JK_CRIT_SEC cs;
    /*其名下的workers*/
    lb_sub_worker_t *lb_workers;
    unsigned int num_of_workers;
    int sticky_session;
    int sticky_session_force;
    int recover_wait_time;
    int max_reply_timeouts;
    int retries;
    int retry_interval;
    int lbmethod;
    int lblock;
    int maintain_time;
    unsigned int max_packet_size;
    unsigned int next_offset;
    /* Session cookie */
    char session_cookie[JK_SHM_STR_SIZ+1];
    /* Session path */
    char session_path[JK_SHM_STR_SIZ+1];
    };
    lb_sub_worker是由lb_worker支配的ajp_worker。当然lb_sub_worker有不同的类型。
    它们的实际类型存储在ajp_worker中。
    dist/common/jk_lb_worker.h
    struct lb_sub_worker
    {
    /* 包含ajp_worker的回调函数及其ajp_worker结构体*/
    jk_worker_t *worker;
    /* Shared memory worker data */
    jk_shm_lb_sub_worker_t *s;
    char name[JK_SHM_STR_SIZ+1];
    /* Sequence counter starting at 0 and increasing
    * every time we change the config
    */
    volatile unsigned int sequence;
    /* route */
    char route[JK_SHM_STR_SIZ+1];
    /* worker domain */
    char domain[JK_SHM_STR_SIZ+1];
    /* worker redirect route */
    char redirect[JK_SHM_STR_SIZ+1];
    /* worker distance */
    int distance;
    /* current activation state (config) of the worker */
    int activation;
    /* Current lb factor */
    int lb_factor;
    /* Current worker index */
    int i;
    /* Current lb reciprocal factor */
    jk_uint64_t lb_mult;
    };
    typedef struct lb_sub_worker lb_sub_worker_t;
    4.2 ajp_worker
    ajp_worker是具体工作的worker,对应后端一个tomcat应用服务。
    dist/common/jk_ajp_common.c
    struct ajp_worker
    {
    /* 包含ajp_worker的回调函数*/
    jk_worker_t worker;
    /* Shared memory worker data */
    jk_shm_ajp_worker_t *s;
    char name[JK_SHM_STR_SIZ+1];
    /* Sequence counter starting at 0 and increasing
    * every time we change the config
    */
    volatile unsigned int sequence;
    jk_pool_t p;
    jk_pool_atom_t buf[TINY_POOL_SIZE];
    JK_CRIT_SEC cs;
    struct sockaddr_in worker_inet_addr; /* Contains host and port */
    unsigned connect_retry_attempts;
    const char *host;
    int port;
    int maintain_time;
    /*
    * Open connections cache...
    *
    * 1. Critical section object to protect the cache.
    * 2. Cache size.
    * 3. An array of "open" endpoints.
    */
    unsigned int ep_cache_sz;
    unsigned int ep_mincache_sz;
    unsigned int ep_maxcache_sz;
    int cache_acquire_timeout;
    ajp_endpoint_t **ep_cache;
    int proto; /* PROTOCOL USED AJP13/AJP14 */
    jk_login_service_t *login;
    /* Weak secret similar with ajp12, used in ajp13 */
    const char *secret;
    /*
    * Post physical connect handler.
    * AJP14 will set here its login handler
    */
    int (*logon) (ajp_endpoint_t * ae, jk_logger_t *l);
    /*
    * Handle Socket Timeouts
    */
    int socket_timeout;
    int socket_connect_timeout;
    int keepalive;
    int socket_buf;
    /*
    * Handle Cache Timeouts
    */
    int cache_timeout;
    /*
    * Handle Connection/Reply Timeouts
    */
    int connect_timeout; /* connect cping/cpong delay in ms (0 means
    disabled) */
    int reply_timeout; /* reply timeout delay in ms (0 means disabled) */
    int prepost_timeout; /* before sending a request cping/cpong timeout
    delay in ms (0 means disabled) */
    int conn_ping_interval; /* interval for sending keepalive cping packets on
    * unused connection */
    int ping_timeout; /* generic cping/cpong timeout. Used for keepalive
    packets or
    * as default for boolean valued connect and
    prepost timeouts.
    */
    unsigned int ping_mode; /* Ping mode flags (which types of cpings should
    be used) */
    /*
    * Recovery options
    */
    unsigned int recovery_opts;
    /*
    * Public property to enable the number of retry attempts
    * on this worker.
    */
    int retries;
    unsigned int max_packet_size; /* Maximum AJP Packet size */
    int retry_interval; /* Number of milliseconds to sleep before
    doing a retry */
    /*
    * HTTP status that will cause failover (0 means disabled)
    */
    unsigned int http_status_fail_num;
    int http_status_fail[JK_MAX_HTTP_STATUS_FAILS];
    };
    4.3 status_worker
    status_worker用于产生一些状态的统计信息。
    dist/common/jk_statuc.c
    struct status_worker
    {
    jk_pool_t p;
    jk_pool_atom_t buf[TINY_POOL_SIZE];
    const char *name;
    const char *css;
    const char *ns;
    const char *xmlns;
    const char *doctype;
    const char *prefix;
    int read_only;
    char **user_names;
    unsigned int num_of_users;
    int user_case_insensitive;
    jk_uint32_t good_mask;
    jk_uint32_t bad_mask;
    jk_worker_t worker;
    jk_worker_env_t *we;
    };
    4.4 jk_worker和 jk_endpoint
    jk_worker是所有worker通用结构体名称, 主要包含的是一些函数指针。它是一个类
    似java中抽象类的概念,各成员函数在从factory函数生产时初始化。
    dist/common/jk_service.h
    struct jk_worker
    {
    /*
    * A 'this' pointer which is used by the subclasses of this class to
    * point to data/functions which are specific to a given protocol
    * (e.g. ajp12 or ajp13 or ajp14).
    */
    void *worker_private;/* 指向ajp_worker,lb_worker结构体 ...*/
    int type;
    /*
    * For all of the below (except destroy), the first argument is
    * essentially a 'this' pointer.
    */
    /* 先于init函数调用,用于分配各类worker结构体的内存,作必要的初始化
    * Given a worker which is in the process of being created, and a list
    * of configuration options (or 'properties'), check to see if it the
    * options are. This will always be called before the init() method.
    * The init/validate distinction is a bit hazy to me.
    * See jk_ajp13_worker.c/jk_ajp14_worker.c and jk_worker.c-
    >wc_create_worker()
    */
    int (JK_METHOD * validate) (jk_worker_t *w,
    jk_map_t *props,
    jk_worker_env_t *we, jk_logger_t *l);
    /*
    * Update worker either from jk_status or reloading from workers.properties
    */
    int (JK_METHOD * update) (jk_worker_t *w,
    jk_map_t *props,
    jk_worker_env_t *we, jk_logger_t *l);
    /*
    * Do whatever initialization needs to be done to start this worker up.
    * Configuration options are passed in via the props parameter.
    */
    int (JK_METHOD * init) (jk_worker_t *w,
    jk_map_t *props,
    jk_worker_env_t *we, jk_logger_t *l);
    /*
    * Obtain an endpoint to service a particular request. A pointer to
    * the endpoint is stored in pend.
    */
    int (JK_METHOD * get_endpoint) (jk_worker_t *w,
    jk_endpoint_t **pend, jk_logger_t *l);
    /*
    * Shutdown this worker. The first argument is not a 'this' pointer,
    * but rather a pointer to 'this', so that the object can be free'd (I
    * think -- though that doesn't seem to be happening. Hmmm).
    */
    int (JK_METHOD * destroy) (jk_worker_t **w, jk_logger_t *l);
    /*
    * Maintain this worker.
    */
    int (JK_METHOD * maintain) (jk_worker_t *w, time_t now, jk_logger_t *l);
    };
    /* jk_endpoint可以称之为通用终端服务结构体,各类worker可能有自己的endpoint结构
    体。比如ajp_worker, 该终端是用来做具体工作的,比如发出请求,接收AJP数据等等。如
    果是lb_worker,该终端是的作用是找出合适ajp_worker, 把任务交给它。* /
    struct jk_endpoint
    {
    jk_uint64_t rd;
    jk_uint64_t wr;
    /*
    * Flag to pass back recoverability status from
    * a load balancer member to the load balancer itself.
    * Depending on the configuration and request status
    * recovery is not allowed.
    */
    int recoverable;
    /*
    * A 'this' pointer which is used by the subclasses of this class to
    * point to data/functions which are specific to a given protocol
    * (e.g. ajp12 or ajp13 or ajp14).
    */
    void *endpoint_private;
    /* 该函数是具体的服务函数
    * Forward a request to the servlet engine. The request is described
    * by the jk_ws_service_t object.
    * is_error is either 0 meaning recoverable or set to
    * the HTTP error code.
    */
    int (JK_METHOD * service) (jk_endpoint_t *e,
    jk_ws_service_t *s,
    jk_logger_t *l, int *is_error);
    /*
    * Called when this particular endpoint has finished processing a
    * request. For some protocols (e.g. ajp12), this frees the memory
    * associated with the endpoint. For others (e.g. ajp13/ajp14), this can
    * return the endpoint to a cache of already opened endpoints.
    *
    * Note that the first argument is *not* a 'this' pointer, but is
    * rather a pointer to a 'this' pointer. This is necessary, because
    * we may need to free this object.
    */
    int (JK_METHOD * done) (jk_endpoint_t **p, jk_logger_t *l);
    };
    4.5 jk_ws_service
    该结构体是与apache相关的一些参数或函数,面向HTTP协议,与AJP协议不太相关。
    dist/common/jk_service.h
    struct jk_ws_service
    {
    /*
    * A 'this' pointer which is used by the subclasses of this class to
    * point to data which is specific to a given web server platform
    * (e.g. Apache or IIS).
    */
    void *ws_private;
    /*
    * Provides memory management. All data specific to this request is
    * allocated within this pool, which can then be reclaimed at the end
    * of the request handling cycle.
    *
    * Alive as long as the request is alive.
    */
    jk_pool_t *pool;
    /*
    * CGI Environment needed by servlets
    */
    const char *method;
    const char *protocol;
    char *req_uri;
    const char *remote_addr;
    const char *remote_host;
    const char *remote_user;
    const char *auth_type;
    const char *query_string;
    const char *server_name;
    unsigned server_port;
    char *server_software;
    jk_uint64_t content_length; /* 64 bit integer that represents the content */
    /* length should be 0 if unknown. */
    unsigned is_chunked; /* 1 if content length is unknown (chunked rq) */
    unsigned no_more_chunks; /* 1 if last chunk has been read */
    jk_uint64_t content_read; /* number of bytes read */
    /*
    * SSL information
    *
    * is_ssl - True if request is in ssl connection
    * ssl_cert - If available, base64 ASN.1 encoded client certificates.
    * ssl_cert_len - Length of ssl_cert, 0 if certificates are not available.
    * ssl_cipher - The ssl cipher suite in use.
    * ssl_session - The ssl session string
    *
    * In some servers it is impossible to extract all this information, in this
    * case, we are passing NULL.
    */
    int is_ssl;
    char *ssl_cert;
    unsigned ssl_cert_len;
    char *ssl_cipher;
    char *ssl_session;
    /*
    * SSL extra information for Servlet 2.3 API
    *
    * ssl_key_size - ssl key size in use
    */
    int ssl_key_size;
    /*
    * Headers, names and values.
    */
    char **headers_names; /* Names of the request headers */
    char **headers_values; /* Values of the request headers */
    unsigned num_headers; /* Number of request headers */
    /*
    * Request attributes.
    *
    * These attributes that were extracted from the web server and are
    * sent to Tomcat.
    *
    * The developer should be able to read them from the ServletRequest
    * attributes. Tomcat is required to append org.apache.tomcat. to
    * these attribute names.
    */
    char **attributes_names; /* Names of the request attributes */
    char **attributes_values; /* Values of the request attributes */
    unsigned num_attributes; /* Number of request attributes */
    /*
    * The route is in use when the adapter load balance among
    * several workers. It is the ID of a specific target in the load balance
    * group. We are using this variable to implement target session
    * affinity
    */
    const char *route;
    /* Temp solution for auth. For native1 it'll be sent on each request,
    if an option is present. For native2 it'll be sent with the first
    request. On java side, both cases will work. For tomcat3.2 or
    a version that doesn't support secret - don't set the secret,
    and it'll work.
    */
    const char *secret;
    /*
    * Area to get POST data for fail-over recovery in POST
    */
    jk_msg_buf_t *reco_buf;
    int reco_status;
    /*
    * If set call flush after each write
    */
    int flush_packets;
    /*
    * If set call flush after AJP13_SEND_HEADERS.
    */
    int flush_header;
    /*
    * service extensions
    */
    svc_extension_t extension;
    /*
    * JK_TRUE if response headers have been sent back
    */
    int response_started;
    /*
    * JK_TRUE if response should not be send to the client
    */
    int response_blocked;
    /*
    * HTTP status sent from container.
    */
    int http_response_status;
    /* Uri worker map. Added for virtual host support
    */
    jk_uri_worker_map_t *uw_map;
    /* 下面这些回调函数实现都可以在mod_jk.c找到
    * Callbacks into the web server. For each, the first argument is
    * essentially a 'this' pointer. All return JK_TRUE on success
    * and JK_FALSE on failure.
    */
    /*
    * Send the response headers to the browser.
    */
    int (JK_METHOD * start_response) (jk_ws_service_t *s,
    int status,
    const char *reason,
    const char *const *header_names,
    const char *const *header_values,
    unsigned num_of_headers);
    /*
    * Read a chunk of the request body into a buffer. Attempt to read len
    * bytes into the buffer. Write the number of bytes actually read into
    * actually_read.
    */
    int (JK_METHOD * read) (jk_ws_service_t *s,
    void *buffer,
    unsigned len, unsigned *actually_read);
    /*
    * Write a chunk of response data back to the browser.
    */
    int (JK_METHOD * write) (jk_ws_service_t *s,
    const void *buffer, unsigned len);
    /*
    * Flush a chunk of response data back to the browser.
    */
    void (JK_METHOD * flush) (jk_ws_service_t *s);
    /*
    * Done with sending response back to the browser.
    */
    void (JK_METHOD * done) (jk_ws_service_t *s);
    /*
    * If set do not reuse socket after each full response
    */
    int disable_reuse;
    /*
    * Add more data to log facilities.
    */
    void (JK_METHOD * add_log_items) (jk_ws_service_t *s,
    const char *const *log_names,
    const char *const *log_values,
    unsigned num_of_items);
    /*
    * Iterate through all vhosts
    */
    void *(JK_METHOD * next_vhost) (void *d);
    /*
    * String representation of a vhost
    */
    void (JK_METHOD * vhost_to_text) (void *d, char *buf, size_t len);
    /*
    * Get uw_map associated with a vhost
    */
    jk_uri_worker_map_t *(JK_METHOD * vhost_to_uw_map) (void *d);
    };
    4.6 共享内存中一些数据结构
    共享内存中的数据结构基本上都是记录之用。有些参数在运行中会实时变化。
    dist/common/jk_shm.h
    /** jk shm generic worker record structure */
    struct jk_shm_worker_header
    {
    int id;
    int type;
    /* worker name */
    char name[JK_SHM_STR_SIZ+1];
    /* Sequence counter starting at 0 and increasing
    * every time we change the config
    */
    volatile unsigned int sequence;
    };
    typedef struct jk_shm_worker_header jk_shm_worker_header_t;
    /** jk shm ajp13/ajp14 worker record structure */
    struct jk_shm_ajp_worker
    {
    jk_shm_worker_header_t h;
    /* Configuration data mirrored from ajp_worker */
    int cache_timeout;
    int connect_timeout;
    int reply_timeout;
    int prepost_timeout;
    unsigned int recovery_opts;
    int retries;
    int retry_interval;
    unsigned int max_packet_size;
    /* current error state (runtime) of the worker */
    volatile int state;
    /* Statistical data */
    /* Number of currently busy channels */
    volatile int busy;
    /* Maximum number of busy channels
    该参数并非我们的maxbusy,它是该worker自程序运行以来busy的最大值 */
    volatile int max_busy;
    volatile time_t error_time;
    /* Number of bytes read from remote */
    volatile jk_uint64_t readed;
    /* Number of bytes transferred to remote */
    volatile jk_uint64_t transferred;
    /* Number of times the worker was used */
    volatile jk_uint64_t used;
    /* Number of times the worker was used - snapshot during maintenance */
    volatile jk_uint64_t used_snapshot;
    /* Number of non 200 responses */
    volatile jk_uint32_t errors;
    /* Decayed number of reply_timeout errors */
    volatile jk_uint32_t reply_timeouts;
    /* Number of client errors */
    volatile jk_uint32_t client_errors;
    /* Last reset time */
    volatile time_t last_reset;
    volatile time_t last_maintain_time;
    };
    typedef struct jk_shm_ajp_worker jk_shm_ajp_worker_t;
    /** jk shm lb sub worker record structure */
    struct jk_shm_lb_sub_worker
    {
    jk_shm_worker_header_t h;
    /* route */
    char route[JK_SHM_STR_SIZ+1];
    /* worker domain */
    char domain[JK_SHM_STR_SIZ+1];
    /* worker redirect route */
    char redirect[JK_SHM_STR_SIZ+1];
    /* Number of currently busy channels */
    volatile int busy;
    /* worker distance */
    volatile int distance;
    /* current activation state (config) of the worker */
    volatile int activation;
    /* current error state (runtime) of the worker */
    volatile int state;
    /* Current lb factor */
    volatile int lb_factor;
    /* 我们的参数加在这里*/
    volatile int maxbusy;
    /* Current lb reciprocal factor */
    volatile jk_uint64_t lb_mult;
    /* Current lb value */
    volatile jk_uint64_t lb_value;
    /* Statistical data */
    volatile time_t error_time;
    /* Number of times the worker was elected - snapshot during maintenance */
    volatile jk_uint64_t elected_snapshot;
    /* Number of non 200 responses */
    volatile jk_uint32_t errors;
    };
    typedef struct jk_shm_lb_sub_worker jk_shm_lb_sub_worker_t;
    /** jk shm lb worker record structure */
    struct jk_shm_lb_worker
    {
    jk_shm_worker_header_t h;
    /* Number of currently busy channels,该值是其名下ajp_worker的busy值之和*/
    volatile int busy;
    /* Maximum number of busy channels,该值是其名下ajp_worker的max_busy值之和
    */
    volatile int max_busy;
    int sticky_session;
    int sticky_session_force;
    int recover_wait_time;
    int max_reply_timeouts;
    int retries;
    int retry_interval;
    int lbmethod;
    int lblock;
    unsigned int max_packet_size;
    /* Last reset time */
    volatile time_t last_reset;
    volatile time_t last_maintain_time;
    /* Session cookie */
    char session_cookie[JK_SHM_STR_SIZ+1];
    /* Session path */
    char session_path[JK_SHM_STR_SIZ+1];
    };
    typedef struct jk_shm_lb_worker jk_shm_lb_worker_t;

     


    展开全文
  • apache,tomcat已经安装好,并且各自都可以正常的提供服务。通过80端口可以正常访问apache的静态资源,通过8080端口可以正常访问tomcat的资源...通过配置mod_jk的status worker来看Mod_jk是否能正常工作 Status wo...
  • mod_proxy和mod_jk比较

    2017-11-16 15:39:00
    mod_proxy和mod_jk比较 Comparing mod_proxy and mod_jk Authur:Mladen Turk Published at 2007-7-16 3:22:57 See source linkhere 介绍 Apache2.2 本身拥有如mod_proxy这样一系列优秀的模块,它们拥有一部分和mod...
  • mod_jk.so文件

    2018-01-05 18:06:58
    apache需要的mod_jk.so apache2.4需要的mod_jk.so apache需要的mod_jk.so
  • window下完整的apache+mod_jk或mod_proxy+tomcat配置方案,用于负载均衡及动静态页面分离。里面包含有相对应版本的apache、tomcat、mod_jk,已经多个参考文档
  • mod_jk.so和apache

    2018-11-15 22:05:38
    里面包含着apache24版本和相应适合的mod_jk.so,只要解压mod_jk,把里面的mod_jk.so放进apache文件夹的modules文件夹即可。然后再进行代码配置。
  • mod_jk.so1

    2017-11-09 10:41:48
    1) Apache装有一个模块,这个模块叫mod_jk 2) Apache通过80端口负责解析任何静态web内容 3) 任何不能解析的内容,用表达式告诉mod_jk,让mod_jk派发给相关的app server去解释。
  • mod_jk.rar

    2020-07-15 10:04:15
    apache2.4 mod_jk.so for linux 64bit 找了好久可用版本
  • mod_jk.so_1.2.48-64

    2020-08-19 12:42:54
    mod_jk.so 1.2.48版本,windows 64位
  • Apache 2.2.15+mod_jk

    2018-10-24 11:49:12
    Apache 2.2.15+mod_jk
  • mod_jk vs mod_

    2013-03-07 11:07:01
    Apache Tomcat mod_jk Connector Configuration Made Simple In this article, we provide a comprehensive overview of the Apache mod_jk connector, including configuration information, use scenarios, s
  • apache2.2.25_And_mod_jk2.2.3

    2015-12-14 23:38:45
    httpd-2.2.25-win32-x86-openssl-0.9.8y.msi和mod_jk-apache-2.2.3.so,用于apache+tomcat集群
  • mod_jk_1.3.27.dll

    2010-03-31 15:13:08
    mod_jk_1.3.27.dll mod_jk dll
  • 我正在寻找一种在Mac OS X 10.7 Lion或更高版本上安装mod_jk的正确方法.目标是测试Apache HTTPD后面的Tomcat.我发现到目前为止,安装mod_jk的唯一方法是下载源码,然后在控制台中配置它,并进行安装.这不是真的,因为我...
  • [Sat Feb 16 20:39:19.891 2013] [5520:2412] [info] jk_handler::mod_jk.c (2781): Aborting connection for worker=xh [Sat Feb 16 21:46:43.444 2013] [5520:6812] [info] ajp_process_callback::jk_ajp_common....
  • mod_jk-new.rar

    2019-05-22 09:32:04
    apache需要的mod_jk.so
  • mod_jk.so”+apache2.4+tomcat7+mod_jk.so_整合配置,dome+文档

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,407
精华内容 962
关键字:

mod_jk