我需要在 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)