WP detecting incorrect commenter IP on Apache/nginx with CloudFlare (4 posts)

  1. SecGen
    Posted 4 years ago #

    I've been running WordPress on Apache with CloudFlare for a while with no problems (using their Apache plugin which respects their CF-Connecting-IP header).

    I just installed nginx to try and get a performance boost, and so far that's working fine. I've even added 'set_real_ip_from' and 'real_ip_header' to nginx.conf as recommended by CloudFlare. The Apache logs continue to show the correct IP, as does one of the WP statistics plugins I use.

    Commenter IPs, however, are not correct and all show as the IP of my server. Any ideas on what could be causing this?

  2. SecGen
    Posted 4 years ago #

    This was fixed by adding the following to wp-config.php:

    if ( ! empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) && preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'] ) )

  3. xxdesmus
    Posted 4 years ago #

    You might also be interested in our WordPress plugin that would also correct this --> http://wordpress.org/extend/plugins/cloudflare/

  4. SecGen
    Posted 4 years ago #

    Hi xxdesmus,

    Thanks. I'm already running this plugin. While the plugin correctly uses the CF-Connecting-IP header, I think that nginx changes this to HTTP_CF_CONNECTING_IP, so the CF plugin doesn't pick it up?

    I may be wrong though. All I know is that it didn't work for me after I installed nginx, and had to use the solution above.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.