环境: nginx + tomcat
nginx.conf 配置:
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://backend_tomcat;
tomat server.conf配置:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%{X-Real-IP}i %l %u %t %r %s %b %D %q %{User-Agent}i %T" resolveHosts="false" />
如上配置就可以在log/local_access.log中查看到访问tomcat的真实IP了。