[英]How to get client ip from node.js express application deployed on AWS Elastic beanstalk?
I am using elastic beanstalk with ngnix proxy server.我正在将弹性 beantalk与ngnix代理服务器一起使用。 my application code was on node.js express framework.我的应用程序代码在 node.js express框架上。 I am trying to access client ip via following code我正在尝试通过以下代码访问客户端 IP
var ip = event.headers['x-forwarded-for'] || event.connection.remoteAddress || event.socket.remoteAddress || event.connection.socket.remoteAddress;
but i always getting same client ip for all incoming request.但我总是为所有传入请求获得相同的客户端 IP。 I think it will be the proxy server's ip address.我认为这将是代理服务器的 IP 地址。
How to access real client address from my application???如何从我的应用程序访问真实的客户端地址???
I defer with @austince, the Client IP will be the first entry in the list for Elastic Beanstalk.我推迟了@austince,客户端 IP 将是 Elastic Beanstalk 列表中的第一个条目。
Example :示例:
X-Forwarded-For: 182.12.12.123, 78.13.13.123 X-Forwarded-For: 182.12.12.123, 78.13.13.123
In case anyone, come looking for example code, here is what I have used in my project.万一有人来寻找示例代码,这是我在我的项目中使用的。
const _ = require('lodash');
const ipAddress = _.split(req.header('X-Forwarded-For'), ',');
ipadd = _.trim(_.first(ipAddress));
Here's the guide from AWS: https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html#x-forwarded-for这是来自 AWS 的指南: https : //docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html#x-forwarded-for
X-Forwarded-For works, but is sometimes a list of IPs that have been hit along the way. X-Forwarded-For有效,但有时是一路上被击中的 IP 列表。 The Client IP should be the first entry in the list for Elastic Beanstalk.客户端 IP 应该是 Elastic Beanstalk 列表中的第一个条目。
Ex :例如:
X-Forwarded-For: client-ip-address, ip-address-1, ip-address-2 X-Forwarded-For:client-ip-address、ip-address-1、ip-address-2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.