简体   繁体   English

Apache Web 服务器无法连接到 Tomcat 服务器

[英]Apache webserver not able to connect to Tomcat server

I have configured Apache Httpd and Tomcat on my local system, by referring to this tutorial: http://www.tutorialspoint.com/white-papers/load-balancing-and-scalability-via-tomcat-clusters.htm .我已经在本地系统上配置了 Apache Httpd 和 Tomcat,参考本教程: http : //www.tutorialspoint.com/white-papers/load-balancing-and-scalability-via-tomcat-clusters.htm I was trying to achive load balancing, but the connection between the webserver and the Tomcat server does not work:我试图实现负载平衡,但网络服务器和 Tomcat 服务器之间的连接不起作用:

In workers.properties fileworkers.properties文件中

workers.tomcat_home=D:/Installed/apache-tomcat-7.0.62
workers.java_home=C:/Program Files/Java/jdk1.6.0_45
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

In httpd.conf filehttpd.conf文件中

# Path to workers.properties
JkWorkersFile D:/Installed/Apache24/conf/workers.properties
# Path to jk logs
JkLogFile D:/Installed/Apache24/logs/mod_jk.log
# Jk log level [debug/error/info]
JkLogLevel info
# Jk log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions for forwarding
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
JkMount /BalServers worker1
JkMount /BalServers/* worker1

I have placed mod_jk.so file in modules folder.我已将mod_jk.so文件放在模块文件夹中。

My webserver is started and running (have tried with http://localhost URL, which shows me Apache home page).我的网络服务器已启动并正在运行(已尝试使用http://localhost URL,它显示了 Apache 主页)。 Tomcat server also works and is able to fetch http://localhost:8080/BalServers/ URL. Tomcat 服务器也可以工作并且能够获取http://localhost:8080/BalServers/ URL。 But when I try http://localhost/BalServers/ URL, nothing is showing up, not even 404 status page.但是当我尝试http://localhost/BalServers/ URL 时,什么都没有显示,甚至没有 404 状态页面。

Please let me know is any other configurations required?请让我知道是否需要任何其他配置?

Here is my server.xml这是我的server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener className="org.apache.catalina.core.JasperListener"/>
 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>

     <Engine jvmRoute="worker1" defaultHost="localhost" name="Catalina">

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
      </Host>
    </Engine>
  </Service>
</Server>

Edit - You have not loaded workers.properties file in your httpd.conf.编辑- 您尚未在 httpd.conf 中加载 workers.properties 文件。 Also, it will be better if you switch on logging and monitor the modjk logs to see where the error is being thrown at.此外,如果您打开日志记录并监视 modjk 日志以查看错误发生的位置会更好。

This is the template you can follow for a successful mod_jk based load balancing.这是您可以遵循的成功基于 mod_jk 的负载平衡的模板。

httpd.conf配置文件

LoadModule    jk_module  modules/mod_jk.so

# This is missing in your httpd.conf
JkWorkersFile conf/workers.properties  
JkLogFile     logs/mod_jk.log  
JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "  
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories  
JkRequestLogFormat     "%w %V %T"

#Use multiple context roots if necessary. But I follow the below.
JkMount  /* balancer

If you want a VirtualHost to be configured, wrap this inside a <VirtualHost *:80> or so如果要配置 VirtualHost,请将其包装在<VirtualHost *:80>左右

And then the workers.properties below然后是下面的 workers.properties

worker.list=balancer

worker.worker1.type=ajp13  
worker.worker1.port=8009
worker.worker1.host=172.16.2.31

worker.worker2.type=ajp13
worker.worker2.port=8009
worker.worker2.host=172.16.2.42  


worker.balancer.type=lb
worker.balancer.method=B
worker.worker2.lbfactor=1
worker.balancer.balance_workers=worker1,worker2
#If sticky session is required
worker.loadbalancer.sticky_session=True

Have a look at these links看看这些链接

Tomcat Server Configuration Doc Tomcat 服务器配置文档

Mulesoft Tutorial Mulesoft 教程

Apache Documentation Apache 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM