【发布时间】:2018-05-14 07:57:53
【问题描述】:
我需要在 nodeJs 中获取客户端真实 IP 地址,当使用 nginx 代理服务器时,我总是得到我的 localhost(127.0.0.1)。谁能帮我解决这个问题? 这是我的代码
app.set('trust proxy', 'loopback');
app.use(function(req, res, next) {
app.ipInfo = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
next();
});
【问题讨论】:
-
您使用的是哪个代理?
-
我在节点前面有 nginx 服务器作为代理。
标签: node.js http express proxy ip