如何从部署在AWS Elastic beanstalk上的node.js express应用程序获取客户端ip?

如何从部署在AWS Elastic beanstalk上的node.js express应用程序获取客户端ip?,node.js,amazon-web-services,amazon-elastic-beanstalk,http-proxy,Node.js,Amazon Web Services,Amazon Elastic Beanstalk,Http Proxy,我正在使用elasticbeanstalk和ngnix代理服务器。我的应用程序代码在node.jsexpressframework上。我正在尝试通过以下代码访问客户端ip var ip=event.headers['x-forwarded-for']|| event.connection.remoteAddress| event.socket.remoteAddress|| event.connection.socket.remoteAddress以下是AWS的指南: X-Forwarded-

我正在使用elasticbeanstalkngnix代理服务器。我的应用程序代码在node.jsexpressframework上。我正在尝试通过以下代码访问客户端ip

var ip=event.headers['x-forwarded-for']||
event.connection.remoteAddress|
event.socket.remoteAddress||

event.connection.socket.remoteAddress以下是AWS的指南:

X-Forwarded-For起作用,但有时是一个沿途受到攻击的IP列表。客户端IP应该是Elastic Beanstalk列表中的最后一个条目

Ex

X-Forwarded-For:ip-address-1、ip-address-2、客户端ip地址


我推迟@austince,客户机IP将是Elastic Beanstalk列表中的第一个条目

示例

X-For:182.12.12.123、78.13.13.123

如果有人来找示例代码,下面是我在项目中使用的代码

const=require('lodash');
常量ipAddress=u.split(请求头('X-Forwarded-For'),',');
ipadd=0.trim(0.first(ipAddress));

您在这方面找到AWS的好文档了吗?令人愤慨的是,它们如此模棱两可……@austince这是我在Elastic Beanstalk实例中观察到的行为。它也是我的第一个例子,使用nginx运行AWS Linux 2