问题原文
原帖链接 · Ali Hashemi · CC BY-SA 3.0
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?
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 3.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
