Get the App
SLTechnology News&Howtos  ›  Servers  › 

Nginx reverse proxy tomcat, logging real IP

Shulou Source: shulou.com Published: 2022-06-02 14:39:34 11月15日 Update

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:

Tags: File log agent configuration lieutenant general client client module Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei macOS vpn Xiaomi