1

I use Drupal 7 at a share hosting account (with apache server) and I use Cloudflare.com CDN. Cloudflare ip token (at webform etc) shows cloudflare IP instead of visitor's original IP.

At settings.php I put

$conf['reverse_proxy'] = TRUE;
$conf['reverse_proxy_header'] = 'HTTP_CF_CONNECTING_IP';

These did not seem to work.

What seems to work was: the instructions given by cloudflare for PHP

if ($_SERVER["HTTP_CF_CONNECTING_IP"]) {$_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_CF_CONNECTING_IP"]; }  

or alternatively what was written at drupal cloudflare module (which is only for drupal 6 and not 7)

$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"] ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER["REMOTE_ADDR"]; 

The questions are

  • why the typical drupal settings ($conf['reverse_proxy_header) did not work, and how can I make them work?
  • If not, then which of the 2 solutions that worked for me is more secure or better?
  • Should I setup $conf['reverse_proxy_addresses'] with cloudflare ips, or it's useless since $conf['reverse_proxy_header'] does not work anyway?
3
  • I checked it out with one of our API guys & option 2 looks to be the way to go. Is your host not willing to install mod_cloudflare? This is perhaps the easiest way to do this. – damoncloudflare Mar 13 '12 at 22:41
  • The question is for hosts that are not using mod_cloudflare. I am expecting someone to answer if there is a way to use the normal drupal $conf at settings.php, without resorting in extra php code, not documented by drupal. How drupal is supposed to work with those $conf value? Am I doing something wrong, or there is a bug in drupal? – john Mar 13 '12 at 22:45
  • which of the 2 solutions that worked for me is more secure or better? Should I setup $conf['reverse_proxy_addresses'] with cloudflare ips, or it's useless since $conf['reverse_proxy_header'] does not work anyway? – john Apr 4 '12 at 22:30
2

Why don't you install the CloudFlare - Free Reverse Proxy, Firewall, and Global CDN module? The module comes with instructions on how to solve this problem:

Installation Instructions:

Install and Enable this module. Add one line of code at the end of your settings.php file:

$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"] ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER["REMOTE_ADDR"];

Save your email address and CloudFlare API key to the CloudFlare administration screen on your Drupal web site (admin/settings/cloudflare).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.