apache反向代理tomcat时x-forwarded-for为null的问题
来源:互联网 发布:水冶豫广网络缴费 编辑:程序博客网 时间:2024/05/29 06:29
apache 在用ProxyPass时会自动在header中设置X-Forwarded-For X-Forwarded-Host和X-Forwarded-Server (http://httpd.apache.org/docs/2.2/mod/mod_proxy.html)
如果tomcat后端不做设置, 在jsp中用out.println("x-forwarded-for:" + request.getHeader("x-forwarded-for") + "<br>");能获取到客户ip,
由于在用nginx做前置代理时为了https也能访问,要让out.println("x-forwarded-proto:" + request.getHeader("x-forwarded-proto") + "<br>");能获取到真实的值需要在tomcat的server.xml
中设置value:
<Valve
className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
protocolHeader="x-forwarded-proto"
/>
这样设置后的tomcat,用于Apache做前置代理时request.getHeader("x-forwarded-for")获取到null。在https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html
中有:
所有在tomcat的server.xml中设置了上述参数后会造成request.getHeader("x-forwarded-for")获取的值为null,但用request.getRemoteAddr()就能获取真实客户ip了。
另外要用request.getHeader("x-forwarded-proto")获取值需要在apache设置中加入RequestHeader set X-Forwarded-Proto "https"(在https的设置中,在http设置中用http)
- apache反向代理tomcat时x-forwarded-for为null的问题
- nginx反向代理时,X-Forwarded-For 如何设置
- nginx反向代理时,X-Forwarded-For 如何设置
- nginx反向代理时,X-Forwarded-For 如何设置
- 反向代理与 Real-IP 和 X-Forwarded-For
- 反向代理与Real-IP和X-Forwarded-For
- request.getHeader("x-forwarded-for") = null ?
- Nginx做代理时X-Forwarded-For信息头的处理
- Nginx做代理时X-Forwarded-For信息头的处理
- Nginx代理中X-Forwarded-For
- Nginx代理中X-Forwarded-For
- Tomcat Access Log记录X-Forwarded-For
- apache+tomcat反向代理
- apache反向代理问题
- Apache proxy tomcat session 为null 问题
- Apache proxy tomcat session 为null 问题
- x-forwarded-for的深度挖掘
- x-forwarded-for的深度挖掘
- 黑马程序员--Java笔记05--继承 extends 和接口 interface
- Hibernate 映射文件属性介绍
- Replace Template and delete the tables in the drawing
- 绑定MAC的静态IP配置路由器
- Windows 下安装 swoole 具体步骤
- apache反向代理tomcat时x-forwarded-for为null的问题
- reflect 库使用小结
- SQLServer错误目录(持续更新中···)
- 用adb将手机/data/data/com.android.providers.contacts/databases下的contacts2.db拷贝到电脑上
- STL中sort()的相关运用
- 黑马程序员--Java笔记06--多态
- linux搭建git服务器
- [leetcode] 162 Find Peak Element(二分)
- 黑马程序员--Java笔记07--异常