banner
moeyy

moeyy

一条有远大理想的咸鱼。
github
mastodon
email

Get the real IP of visitors after using CDN in Wordpress.

Title: Obtaining the Real IP Address of Visitors After Using CDN in Wordpress
Tags: WordPress
ID: '1037'
Categories:

    • Tutorial
      Date: 2019-11-17 19:13:44
      Cover:
      AI: true

Explanation: Due to using a Hong Kong server to bypass the record filing process in China, when viewing comments in the Wordpress backend, the IP address displayed is that of the CDN instead of the actual visitor's IP address. This is not a significant issue. However, recently, when the Limit Login Attempts plugin sent me an email about someone attempting to brute force the backend password, the displayed IP address was also that of the CDN. It is troublesome to block the CDN IP address, so I searched for a solution and found one in a tutorial on Baidu Baike.

  1. Use software like WinSCP to open the wp-config.php file in Wordpress.
  2. Paste the following code after the first <!--?php tag in the wp-config.php file:
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$list = explode(‘,’,$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $list[0];
}
  1. Save the modified file.
  2. Update the wp-config.php file in your Wordpress directory.

Principle Analysis: In our Wordpress, we use the "REMOTE_ADDR" function to obtain the visitor's IP address. By replacing the function with "HTTP_X_FORWARDED_FOR", it usually solves the issue.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.