4

I am hosting a WordPress site on Heroku with Nginx. DNS is behind CloudFlare.

My WordPress plugins reports Heroku IPs instead of real client IPs.

I have the following Nginx rules:

location / {
    try_files $uri $uri/ /index.php?$args;

    proxy_set_header    X-Real-IP       $remote_addr;
    proxy_set_header    Host            $host;
    proxy_set_header    X-Forwarded-For $http_cf_connecting_ip;
}

# Allow for internal Heroku router - 10.x.x.x
set_real_ip_from  10.0.0.0/24;

# Allow for external CloudFlare proxies - https://www.cloudflare.com/ips
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/12;

# Recursively process X-Forwarded-For header
real_ip_recursive on;
real_ip_header    X-Forwarded-For;

Full config can be found on https://github.com/wphuman/heroku-buildpack-php/tree/master/conf/nginx

Whenever WordPress plugins try to read the remote address header $_SERVER['REMOTE_ADDR'], they read a 10.x.x.x Heroku IP.

Is there any way to set REMOTE_ADDR to real client IPs?

Thanks

4
  • Let it read X-Real-IP header.
    – Alexey Ten
    Jan 6, 2015 at 13:59
  • I have no control on the WordPress plugins. Is there any way to set REMOTE_ADDR to X-Real-IP?
    – tangrufus
    Jan 6, 2015 at 22:30
  • No. Configure your wordpress. I'm sure there is somw way to do it. Wordpress behind nginx/apache is really common configuration
    – Alexey Ten
    Jan 6, 2015 at 22:39
  • You forgot to include your complete nginx configuration, and it is almost certainly necessary here. Please edit your question to include the configuration, not just a link to it. Jul 8, 2015 at 13:47

1 Answer 1

-2

Just add this line:

proxy_set_header REMOTE_ADDR $remote_addr;
2
  • 7
    This does not work, as nginx cant force the REMOTE_ADDR because it is determined by proxied server as where the request is coming from that is why there are additional headers needs to be set by proxy server proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; and by proxied server those needs to be checked and overwrited as remote_addr. hope this helps.
    – user138870
    Oct 28, 2016 at 1:39
  • This does not work. because the backend server takes $remote_addr variable from socket options and when you set REMOTE_ADDR, actually you set $http_remote_addr not $remote_addr. Oct 23, 2019 at 8:47

Not the answer you're looking for? Browse other questions tagged .