解压 tomcat.apache.org 上提供的 tomcat9 包后,将 mod_jk 配置为:
workers.tomcat_home=/opt/apache-tomcat-9.0.34
workers.java_home=/opt/jdk-13
ps=/
worker.list=ajp13_worker
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
当我将 WAR 部署到 webapps 目录并尝试访问它时,浏览器显示此错误:
在 mod_jk 日志中,我得到了这个:
[Sat Apr 25 08:45:49.187 2020] [16060:139700132441152] [info] jk_open_socket::jk_connect.c (816): connect to 127.0.0.1:8009 failed (errno=111)
[Sat Apr 25 08:45:49.187 2020] [16060:139700132441152] [info] ajp_connect_to_endpoint::jk_ajp_common.c (1065): (ajp13_worker) Failed opening socket to (127.0.0.1:8009) (errno=111)
[Sat Apr 25 08:45:49.187 2020] [16060:139700132441152] [error] ajp_send_request::jk_ajp_common.c (1725): (ajp13_worker) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=111)
[Sat Apr 25 08:45:49.187 2020] [16060:139700132441152] [info] ajp_service::jk_ajp_common.c (2775): (ajp13_worker) sending request to tomcat failed (recoverable), because of error during request sending (attempt=2)
[Sat Apr 25 08:45:49.187 2020] [16060:139700132441152] [error] ajp_service::jk_ajp_common.c (2796): (ajp13_worker) connecting to tomcat failed (rc=-3, errors=2, client_errors=0).
[Sat Apr 25 08:45:49.187 2020] [16060:139700132441152] [info] jk_handler::mod_jk.c (2991): Service error=-3 for worker=ajp13_worker
我的server.xml
文件已经取消注释此部分:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector protocol="AJP/1.3"
address="::1"
port="8009"
redirectPort="8443" />
如果我尝试使用类似http://mydomain:8080/app
名为的webapp的某个id进行访问app
,则可以正常工作。但如果没有:8080
,则应该通过mod_jk进行访问,我收到了错误。
谁能告诉我这里出了什么问题?
答案1
添加secretRequired="false"
到其中<Connector>
即可server.xml
为我修复该问题。
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector protocol="AJP/1.3"
port="8009"
redirectPort="8443"
secretRequired="false" />
答案2
您正在尝试通过 IPv4 进行连接(127.0.0.1 是赠品),但您告诉 Tomcat 在 IPv6 本地主机(::1)上监听。
也许告诉 Tomcat 也使用 IPv4(tomcat 绑定到 ipv4)。
答案3
我使用了以下内容:
setsebool -P httpd_can_network_connect=1
您可以使用此命令来检查其是否设置正确:
getsebool -a | grep httpd
您应该看到:
httpd_can_network_connect --> on