Support » Fixing WordPress » WP detecting incorrect commenter IP on Apache/nginx with CloudFlare

  • 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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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’] ) )
    $_SERVER[‘REMOTE_ADDR’] = $_SERVER[‘HTTP_CF_CONNECTING_IP’];

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

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP detecting incorrect commenter IP on Apache/nginx with CloudFlare’ is closed to new replies.