tomcat配置问题的解决方案

1、tomcat 8.5.51后对请求的路径中包含花括号的预警提醒

异常描述:

28-Oct-2020 15:30:46.212 SEVERE [http-nio-8080-exec-4] org.apache.catalina.core.AprLifecycleListener.init An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

解决办法:

在conf/catalina.properties中最后添加2行:

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

参考:https://blog.csdn.net/ljheee/article/details/82051755

2、nginx代理调整到tomcat服务器。

异常描述:通过nginx代理tomcat后,tomcat的访问日志中显示的是代理服务器所在地址,而不是真实的客户IP地址。

28-Oct-2020 15:29:48.410 SEVERE [main] org.apache.catalina.core.AprLifecycleListener.init An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

解决方案:

    在tomcat配置文件server.xml中的<host>节点下添加如下配置:

<!--支持跳转 -->
<Valve className="org.apache.catalina.valves.RemoteIpValve"
                       remoteIpHeader="x-forwarded-for"
                       remoteIpProxiesHeader="x-forwarded-by" />
<!--在tomcat的日志中显示真实客户端地址 -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
               prefix="localhost_access_log" suffix=".txt"
               pattern="%{X-Real-IP}i %l %u %t &quot;%r&quot; %s %b" /> 

参考:https://www.cnblogs.com/xiaochina/p/9252916.html


版权声明:本文为dhx20022889原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。