Node.js 如何获取真实 IP?(Nginx 服务器)

在 nginx.conf 中配置:

proxy_set_header  X-Real-IP  $remote_addr;

在 node.js 中获取 ip:

const ip = req.headers['x-real-ip'] || req.connection.remoteAddress;

https://stackoverflow.com/a/18481747/3054511

猜你喜欢

转载自blog.csdn.net/henryhu712/article/details/87915589