直接上代码:
var ip = req.header('x-forwarded-for') || req.connection.remoteAddress;
5 回复
.replace(':remote-addr’, req.headers[‘x-forwarded-for’] || req.connection.remoteAddress)
我也遇到过类似的问题,nginx反向代理后,需要改一下配置 http://blog.fens.me/nodejs-nginx-log4js/