Apache使用Mod_JK代理多个Tomcat实例

时间:2016-10-06 15:39:54

标签: apache tomcat mod-jk

我有一个Apache服务器,它假设将所有请求重定向到两个Tomcat实例:“geonetwork”和“geoserver”。

它们都可以从Apache服务器访问,但不知怎的,我无法使重定向工作。

我的主机文件如下所示:

<VirtualHost *:80>
        ServerName localhost
        ServerAdmin someemail@email.com
        DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
        ServerName geonetwork
        ServerAdmin someemail@email.com
        DocumentRoot /usr/local/tomcat_gn/webapps

        <Directory "/usr/local/tomcat_gn/webapps">
           #Options MultiViews FollowSymLinks
           Options All
           AllowOverride all
           Require all granted
        </Directory>

        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JkMount /geonetwork|/* gn_worker
</VirtualHost>

<VirtualHost *:80>
        ServerName geoserver
        ServerAdmin someemail@email.com
        DocumentRoot /usr/local/tomcat_gs/webapps

        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JkMount /geoserver|/* gs_worker
</VirtualHost>


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

documentRoot指令,指向挂载tomcat实例的目录。

这是worker.properties文件:

#
worker.list=gn_worker,gs_worker

#
#------ ajp13_worker WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
# 

# 
# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.
# 
worker.gs_worker.port=8009
worker.gs_worker.host=geoserver
worker.gs_worker.type=ajp13

worker.gn_worker.port=8009
worker.gn_worker.host=geonetwork
worker.gn_worker.type=ajp13
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.gs.lbfactor=1
worker.gn.lbfactor=1

#
# Specify the size of the open connection cache.
#worker.ajp13_worker.cachesize

# 
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
#---------------------------------------------------------------------
#

#
# The loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=gn_worker,gs_worker

最让我感到震惊的是,第一个虚拟主机始终有效。所以在这个例子中,它解析为apache root,但是如果我把geonetwork或geoserver解析成正确的:

http://localhost/geonetworkhttp://localhost/geoserver

我正在跑出想法来调试这个!有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我想您可能忘记在每个虚拟主机中执行JkMount之前包含mod_jk配置:

# Load mod_jk module
LoadModule jk_module modules/tomcat-connector/mod_jk.so

# Add the module (activate this lne for Apache 1.3)
# AddModule     mod_jk.c
# Where to find workers.properties
JkWorkersFile conf/extra/workers.properties
# Where to put jk shared memory
JkShmFile     logs/mod_jk.shm
# Where to put jk logs
JkLogFile     logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info


<VirtualHost *:80>
        ServerName localhost
        ServerAdmin someemail@email.com
        DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
        ServerName geonetwork
        ServerAdmin someemail@email.com
        DocumentRoot /usr/local/tomcat_gn/webapps

        <Directory "/usr/local/tomcat_gn/webapps">
           #Options MultiViews FollowSymLinks
           Options All
           AllowOverride all
           Require all granted
        </Directory>

        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JkMount /geonetwork|/* gn_worker
</VirtualHost>

<VirtualHost *:80>
        ServerName geoserver
        ServerAdmin someemail@email.com
        DocumentRoot /usr/local/tomcat_gs/webapps

        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JkMount /geoserver|/* gs_worker
</VirtualHost>

在我不必操纵映射应用程序的上下文根时,我个人更喜欢mod_jk,因为在使用平衡器时我可以通过状态工作者进行动态管理,但这只是我的看法。

相关问题