我们有一个独立的spring-boot应用程序,我们希望在其中设置访问日志模式
> X-forwarded-for标头存在于请求中:它应作为第一个字段包含在日志中
> X-forwarded-for header在请求中不存在:它应该被远程ip地址替换
当我们使用以下设置运行我们的应用程序时,我们只获取远程IP地址
server.tomcat.accesslog.directory=%r" %s %b
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.suffix=.log
例如:
192.168.25.265 - - - [12/Sep/2016:10:20:56 +0200] "GET /myapp HTTP/1.1" 200 125922
我们还尝试将属性server.tomcat.accesslog.pattern设置为
%h %{X-Forwarded-For}i %l %u %t "%r" %s %b
然后我们得到远程IP地址和X-forwarded-for标头值.
例如:
192.168.25.265 192.168.21.65 - - - [12/Sep/2016:10:20:56 +0200] "GET /myapp HTTP/1.1" 200 125922
但是,基于链接https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html,当x-forwarded-for不存在时,tomcat支持包含远程ip地址的此要求.这可以通过添加属性’requestAttributesEnabled’来实现
我们尝试添加该属性
server.tomcat.accesslog.requestAttributesEnabled
但没有发生任何影响.
它似乎没有实现,因为它不存在于此:http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
我们使用EmbeddedServletContainerCustomizer的实现实现了一个变通方法,如How do I configure the location and name of tomcat access log in spring-boot?所述,
我们在哪里添加:
accessLogValve.setRequestAttributesEnabled(true);
它按预期工作.
但是我们希望能够通过spring-boot将requestAttributesEnabled设置为配置属性,如:
server.tomcat.accesslog.requestAttributesEnabled=true
而不是需要在我们的所有服务中使用此定制器.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。