How to see visitor’s real IP with Cloudways and Cloudflare

If you’re using Cloudflare in front of your Cloudways site, you’ll notice that all the visitors come through with the IP address of It’s easy enough to fix this. Cloudways posted a useful article about it, but it misses one critical thing – the WordPress configuration!

First, head to your server configuration on Cloudways, and choose Settings & Packages > Advanced:

Scroll down until you fine the WAF Module setting, and change that to Cloudflare:

You’ll also need to restart your Apache service.

Then, for each of your WordPress sites, you’ll need to add this code to your wp-config.php :

if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
    $xffaddrs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); 
    $_SERVER['REMOTE_ADDR'] = $xffaddrs[0]; 

Once you’ve done that, look in the logs, or post yourself a test comment to verify that the IP address is coming through correctly. Should be all good!

One thought on “How to see visitor’s real IP with Cloudways and Cloudflare

  1. Thank you for sharing it!
    I was analyzing the traffic for a customer that is hosted on CloudWays and I didn’t understood what was going on.

Leave a Reply

Your email address will not be published. Required fields are marked *