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

passing real IP address from one nginx instance to another and writing it in the logs

· 52CE 我爱测

Moving a request to my internal nginx server I add to the call: proxy_set_header X-Real-IP $remote_addr; when I try to print this value in the log the internal nginx the container crashes: log_format verbose ' Real: $X-Real-IP ';…

问题原文

原帖链接 · Dani · CC BY-SA 4.0

Moving a request to my internal nginx server I add to the call:

proxy_set_header X-Real-IP $remote_addr;

when I try to print this value in the log the internal nginx the container crashes:

log_format verbose ' Real: $X-Real-IP ';

What am I doing wrong? (I also tried with "" around the variable, it didn't help.)

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 4.0

The server receives X-Real-IP as one of the headers in the HTTP request. Nginx makes each of the request header values available as a variable.

The variable name for http request header values begins with $http_. The header name is converted to lowercase, and each hyphen is replaced with an underscore.

For example X-Real-IP is available as $http_x_real_ip

See this document for details.

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

资料来源与适用范围

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

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

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