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

Published: 2020-12-15

Windows Server Settings

If security software is installed on the server, it may cause the DLL for obtaining real IP logs to run abnormally, resulting in failure to obtain the real IP address.

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

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. Check whether the following two modules are installed on your server: (“ISAPI Filters” and “ISAPI and CGI Restrictions”). If they are not installed, 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 at the site level.

image.png

5. Enter a name for the filter (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 logs; 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;


Using BaoTa as an example

Log in to the BaoTa Panel backend >> Software Store >> Runtime Environment >> click the corresponding “Settings” on the right side of nginx >> in nginx management, click “Modify Configuration” on the left >> add the following two lines of code after http{, as shown below:

image.png