大网数据广告活动
服务器运维问答

Configuring nginx to log original requestor IP (instead of IP of forward proxy)

· 52CE 我爱测

On an nginx-enabled website I maintain, some visitors are behind a certain forward proxy. Since requests pass through the proxy's servers, the HTTP Request IP address in these cases is always from proxy servers instead of from th…

问题原文

原帖链接 · Hassan Baig · CC BY-SA 3.0

On an nginx-enabled website I maintain, some visitors are behind a certain forward proxy. Since requests pass through the proxy's servers, the HTTP Request IP address in these cases is always from proxy servers instead of from the original requestor.

However, the proxy ensures including the original requestor IP in a separate HTTP header field called X-IORG-FBS-UIP. It can also be found in X-FORWARDED-FOR.

In nginx access logs, I notice the proxy IP is what shows up for all these users, not the real IP. How can I configure nginx such that the original requestor IP is logged by nginx, and not the proxy one? An illustrative example would be great; thanks in advance!


p.s. my nginx is v 1.4.6

已采纳解答

原帖链接 · Andrei · CC BY-SA 3.0

This is done using set_real_ip_from to update the $remote_addr variable based on a custom header. For example, /etc/nginx/conf.d/proxies_acl.conf can be created as follows, to set the client IP variable based on the X-IORG-FBS-UIP header for requests proxied by 1.2.3.0/22 and 23.22.20.0/22:

set_real_ip_from 1.2.3.0/22;
set_real_ip_from 23.22.20.0/22;
real_ip_header X-IORG-FBS-UIP;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。