除了客户端 IP 之外,还带有客户端套接字端口的 nginx 代理标头

Rob*_*ade 1 proxy nginx

我正在尝试修改我的 nginx 配置,以便我可以传递原始客户端的 IP 以及客户端的套接字源 TCP 端口,因为当我将连接传递到上游服务器时,它会将源 IP 和端口识别为唯一的源 IP 和端口由nginx而不是客户端打开,即:

\n\n
proxy_set_header X-Real-IP $remote_addr;                              \xe2\x94\x82\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;          \xe2\x94\x82\n
Run Code Online (Sandbox Code Playgroud)\n\n

有 $remote_port 这样的东西吗?我不确定实现这一目标的唯一方法是否是编写自己的模块?

\n

Tan*_*Tat 5

ngx_http_core_module 模块支持名称与 Apache Server 变量匹配的嵌入变量。首先,这些是代表客户端请求头字段的变量,例如$http_user_agent、$http_cookie等。此外还有其他变量:

$remote_port- 客户端端口

来源:http ://nginx.org/en/docs/http/ngx_http_core_module.html#variables