我需要在nodeJs中获得客户端的真实IP地址,当使用nginx代理服务器时,我总是得到我的本地主机(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();
});https://stackoverflow.com/questions/47572601
复制相似问题