Today test the Nginx reverse proxy function, let the Tomcat log to get the user real IP address, Google a bit, is an article content, copied the tomcat configuration file to modify the content, how can not get, magical! Helpless under, carefully read the copy of each line of content, found that the problem, it is estimated that if the search for the article, it is impossible to obtain the real IP address, a small place. To start checking configuration content:
(1) Nigix nginx.conf configuration file:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# # # Confirm no errors, but note:x-real-IP (small red bars)
(2) in the Tomcat server.xml configuration file:
<valve classname= "Org.apache.catalina.valves.AccessLogValve"
directory= "Logs" prefix= "Tomcat_access_log." suffix= ". txt"
pattern= "%a%r%t%{x-real_ip}i" resolvehosts= "false"/>
# # # Attention, attention, see the problem? %{x-real_ip}i not x-real-IP, Universal copy Ah, Bo master How to write the underline, find the problem modified, restart Tomcat, the client real IP address into the log. Oh, who want to copy the content of the article to ensure that no one will be to haha!
This article is from the "Old Wafangdian" blog, please be sure to keep this source http://laowafang.blog.51cto.com/251518/1684104
Nginx Reverse proxy tomcat logs get real IP