nginx代理 tomcat获得真实用户IP
2017年04月08日 21:34:17 cf 阅读数 1825更多
分类专栏: nginx html/js/ajax
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
1.nginx的location中设置 header,如
location /ConfigService/{
proxy_read_timeout 90;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://www.qawe.info:8088/ConfigService/;
}
2.tomcat配置(server.xml)中添加RemoteIpValve配置,如
<Valve
className="org.apache.catalina.valves.RemoteIpValve"
httpServerPort="8088"
httpsServerPort="8443"
remoteIpHeader="x-forwarded-for"
proxiesHeader="x-forwarded-by"
protocolHeader="x-forwarded-proto"
/>