Nginx reverse proxy tomcat, logging real IP
Nginx reverse proxy tomcat, logging real IP
When nginx reverse proxy, if no configuration is added, the proxy IP of nginx will be displayed in the tomcat log. In order to know that the real client accesses IP, you can add the following configuration implementation
Tomcat log file: localhost_access_log.txt
1. Modify nginx.conf
Add to server or location
Proxy_set_header X-Forwarded-For $remote_addr
2. Modify tomcat configuration file
Modify the server.xml file and find in it: className= "org.apache.catalina.valves.AccessLogValve" directory= "logs" module, modify pattern= "% {X-FORWARDED-FOR} I% u...."
After modification, it is as follows: