小编Lia*_*ana的帖子

在节点前使用nginx服务器作为代理时如何获取客户端真实IP

我需要在 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();
});
Run Code Online (Sandbox Code Playgroud)

ip proxy http node.js express

8
推荐指数
1
解决办法
2580
查看次数

标签 统计

express ×1

http ×1

ip ×1

node.js ×1

proxy ×1