Method for obtaining the visitor's real IP in logs after enabling nginx proxy

Published: 2020-12-15

Windows server settings

Installing security software on the server will cause the DLL for obtaining real IP logs to run abnormally, resulting in failure to successfully obtain the real IP address.

The required steps depend on your IIS version. This operation applies to versions above IIS 7.

1. Download the plugin F5XForwardedFor.dll:http://download.west263.net/iis7-rewrite%E6%8F%92%E4%BB%B6/x_forwarded_for.rar

2. Extract F5XForwardedFor.dll and copy it to a directory, for example C:\F5XForwardedFor\, and ensure that the IIS process has read permission for that directory.

3. Confirm whether your server has the following two modules installed: ("ISAPI Filters" and "ISAPI and CGI Restrictions"). If they are not installed, please follow the steps below to install them:

image.png

4. Add "ISAPI Filters", double-click "ISAPI Filters", and click Add:Note: Do not add it on the site

image.png

5. Fill in the filter name (no special requirements), select the DLL file path, and click OK.Add the two DLLs separately 

image.png

image.png



6. Restart the IIS server. After the configuration takes effect, check the IIS log; the real IP address will be displayed after the 127.0.0.1 column.

image.png


Linux server settings

After using a third-party CDN, the address obtained by nginx on the server is the third-party CDN address. Modify the nginx configuration to obtain the real IP address.

Add the following two lines of code after http{


set_real_ip_from 0.0.0.0/0;

real_ip_header X-Forwarded-For;


Take Baota Panel as an example

Log in to the Baota Panel backend >> App Store >> Runtime Environment >> click the corresponding "Settings" on the right side of nginx >> in nginx management click "Config Modification" on the left >> add the following two lines of code after http{, as shown below:

image.png