Get the App
SLTechnology News&Howtos  ›  Servers  › 

Let the localhost_access_log of tomcat get the real IP after using nginx

Shulou Source: shulou.com Published: 2022-06-03 02:53:52 10月03日 Update

Configure nginx

Add the following code under the location node

Proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for

Modify the server.xml configuration file for tomcat

To record the visitor's real IP in Tomcat, refer to the tomcat log configuration syntax described above, simply add the following mode to the log mode:% {X-Real-IP} I

Find the following configuration

Just modify it as follows

View the tomcat access record, which records the client IP address.

Outside:

Set up and record the real IP of visiting customers and the customer access address as follows:

H the IP address of the user accessed. (not the client IP address. To record the visitor's real IP in Tomcat, simply add the following mode to the log mode:% {X-Real-IP} I)

The IP address of the user accessed by% h. If the nginx proxy, it records the nginx server IP, that is, the intranet IP.

Tags: Address customer mode configuration log just client that is visitor user code file server node syntax agent reference service Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology Xiaomi MariaDB Redmi