Mobile app version of vmapp.org
Login or Join
Lee4591628

: Get real user IP behind two reverse proxies This is my environment setup: Server A hosts the site (Nginx + PHP-FPM + Wordpress) Server B is Nginx reverse proxy for server A Cloudflare reverse

@Lee4591628

Posted in: #Cloudflare #Nginx #ReverseProxy #Wordpress

This is my environment setup:


Server A hosts the site (Nginx + PHP-FPM + Wordpress)
Server B is Nginx reverse proxy for server A
Cloudflare reverse proxy is on top of all.


Therefore, user request first go to Cloudflare, then server B and then server A. I've set:

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


on server B. I've also installed Cloudflare wordpress plugin, but Wordpress still gets server B IP address instead of user IP address, detecting Cloudflare IP addresses as originating IPs. :(

Installing Proxy Real IP changes Server B IP addresses to Cloudflare IP addresses, not real user IP.

Any help to get real user IP address at Wordpress end?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Lee4591628

1 Comments

Sorted by latest first Latest Oldest Best

 

@Heady270

When multiple proxies are involved and they all support X-Forwarded-For, they each append a value to it. Cloudflare states this in its documentation.

To get this behavior from nginx it looks like you need to set the real_ip_recursive option.

So on the WordPress side the real IP address of the user will usually be the first IP address in the comma separated value list of the X-Forwarded-For header.

Your WordPress header states that it uses "a regular expression" to match the IP address from that field, but it doesn't state that it can deal with multiple values in that field. You may need to update the code of the plugin to work properly when there are multiple values.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme