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

nginx with real_ip -- log both client remote_addr and proxies address

· 52CE 我爱测

I have an nginx instance set up behind multiple load balancing proxies, and I am using real_ip to get the clients IP address in remote_addr for processing by my Python application. However in my logs I would like to log the proxy…

问题原文

原帖链接 · X-Istence · CC BY-SA 3.0

I have an nginx instance set up behind multiple load balancing proxies, and I am using real_ip to get the clients IP address in remote_addr for processing by my Python application.

However in my logs I would like to log the proxy server that actually made the request, but $remote_addr has now been overwritten, and I can't find anything that says a copy of it is made.

How would I be able to accomplish this?

已采纳解答

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

Your setup may have changed since you posted this question, but I had the same problem and there is finally a solution available. I'll post it here in case Google brings someone else to this page.

As @Michael Hampton♦ indicates in his answer to my own version of this question, nginx has added the variable $realip_remote_addr to the Real_IP module. It holds the original value of $remote_addr, allowing you to use/log both the originating client's IP and the IP of the server that sent the actual request to nginx. This was added to version 1.9.7, as of November 2015.

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

资料来源与适用范围

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

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

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