Nginx如何获取请求客户端的IP地址 [英] nginx how to get the request client ipaddress

查看:1563
本文介绍了Nginx如何获取请求客户端的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ngnix代理到nodejs服务器.我正在尝试在我的nodejs中读取请求客户端的IP地址/主机名,但这始终是

I have ngnix proxying to a nodejs server. I am trying to read the request client ip address/host name in my nodejs, but it's always

::ffff:127.0.0.1

但是在我的nginx访问日志中,我可以看到打印的客户端IP地址,不确定为什么我的nodejs服务器无法获取它.

But in my nginx access log, I can see the client ip address printed, not sure why my nodejs server can't get it.

x.x.x.x - - [24/Aug/2017:14:28:01 -0700] "GET ...."

推荐答案

将以下内容添加到代理NodeJS的nginx配置节中:

Add the following to your nginx configuration stanza that proxies to NodeJS:

proxy_set_header X-Real-IP $remote_addr;

现在您可以在NodeJS中读取标头"X-Real-IP"

Now you can read the header 'X-Real-IP' in NodeJS

这篇关于Nginx如何获取请求客户端的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆