gpt4 book ai didi

spring-boot - Apache 无法连接到新的 tomcat 9 ajp

转载 作者:行者123 更新时间:2023-12-03 20:24:43 60 4
gpt4 key购买 nike

将 Spring boot 的版本从 2.1.4 升级到 2.3.2 后,我的 apache2 无法再(通过 ajp)连接到我的 Spring boot 的嵌入式 tomcat。
它显示以下错误:

[proxy:error] [pid xxxx ] (111)Connection refused: AH00957: AJP: attempt to connect to 10.0.75.1:8500 (10.0.75.1) failed
[proxy_ajp:error] [pid xxxx ] [client xxx ] AH00896: failed to make connection to backend: 10.0.75.1, referer: http://myapp.develop/home/
我的开发环境是这样设置的:
  • 一个 Angular 应用程序(运行在 4200 上的节点服务器)
  • Spring Boot 后端(在 8500 端口上的 tomcat 上设置的 ajp 连接器)
  • 前端 apache2 服务器(在 docker 容器上)设置为将请求重定向到两个应用程序:
    <VirtualHost *:80>
    ServerName myapp.develop

    ProxyPass "/home" "http://10.0.75.1:4200/home"
    ProxyPassReverse "/home" "http://10.0.75.1:4200/home"

    ProxyPass "/backend" "ajp://10.0.75.1:8500/backend"
    ProxyPassReverse "/backend" "ajp://10.0.75.1:8500/backend"

  • 我通过/etc/hosts 上的域名访问我的网络应用程序:myapp.develop
    这是我的spring boot tomcat的配置
       Connector connector = new Connector("AJP/1.3");
    connector.setScheme("http");
    connector.setPort(8500);
    connector.setSecure(false);
    connector.setAllowTrace(false);
    ((AbstractAjpProtocol) connector.getProtocolHandler()).setSecretRequired(false);
    在 app.properties 中:
    tomcat.ajp.port=8500
    tomcat.ajp.remoteauthentication=false
    tomcat.ajp.enabled=true
    这是 tomcat 日志:
    o.s.b.w.e.t.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http) 8500 (http)
    o.a.c.h.Http11NioProtocol : Initializing ProtocolHandler ["http-nio-8080"]
    o.a.c.a.AjpNioProtocol : Initializing ProtocolHandler ["ajp-nio-127.0.0.1-8500"]
    o.a.c.c.StandardService : Starting service [Tomcat]
    o.a.c.c.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
    我怀疑这种变化:
  • 从 8.5.51 开始,AJP 连接器的默认监听地址改为环回地址而不是所有地址。

  • 是什么导致了我这个问题,但我不知道如何解决它。

    最佳答案

    我在升级 tomcat 版本时遇到了类似的问题。将下面提到的属性添加到 ajp 连接器有助于我的情况。

    connector.setProperty("address","0.0.0.0");
    connector.setProperty("allowedRequestAttributesPattern",".*");
    ((AbstractAjpProtocol)connector.getProtocolHandler()).setSecretRequired(false);
    详细说明:
    对于你的疑问:

    In 8.5.51 onwards, the default listen address of the AJP Connector waschanged to the loopback address rather than all addresses.


    在此更新之前,tomcat AJP 连接器愿意接受来自任何 IP 地址的请求,因此不需要明确指定“地址”属性。但是在此更新之后,默认行为是 AJP 连接器愿意接受仅作为 localhost(环回)发出的请求。使用下面列出的“地址”属性将监听范围扩展到不仅是环回地址
    connector.setProperty("address","0.0.0.0"); // OR connector.setProperty("address","::");
    使用以下属性启用所有类型的请求属性(除非您有 header 信息,在这种情况下启用特定的)。具有无法识别的请求属性的请求将被拒绝并返回 403 响应:
    connector.setProperty("allowedRequestAttributesPattern",".*"); 
    使用“secretRequired”属性来定义是否需要与 HTTP 服务器交换 secret 以允许通过 ajp 的请求。如果是,则还要设置“secret”属性。否则请求将失败并显示 403。
    ((AbstractAjpProtocol)connector.getProtocolHandler()).setSecretRequired(false);
    引用: Apache Tomcat 8 Configuration Reference

    Use of the AJP protocol requires additional security considerationsbecause it allows greater direct manipulation of Tomcat's internaldata structures than the HTTP connectors. Particular attention shouldbe paid to the values used for the address, secret, secretRequired andallowedRequestAttributesPattern attributes.

    关于spring-boot - Apache 无法连接到新的 tomcat 9 ajp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63505670/

    60 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com