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
X-Real-IP
header.REMOTE_ADDR
toX-Real-IP
?