如何使用ngrok进行隧道连接时获取真实客户端ip请求

时间:2016-06-07 00:57:36

标签: ngrok

如何确保ngrok转发客户端IP地址?

我的测试代码一直坚持所有请求都来自127.0.0.1,因为ngrok但我想记录实际的客户端IP。负载均衡器通常在X-Forwarded-For或x-real-ip中设置标题,但我不确定ngrok的进程是什么......

  console.log('req.headers[\'x-real-ip\']', req.headers['x-real-ip']);
  console.log('req.headers[\'X-Forwarded-For\']', req.headers['X-Forwarded-For']);
  console.log('req.ip', req.ip );
  console.log('req.connection.remoteAddress', req.connection.remoteAddress);
  console.log('req.connection.remoteAddress', req.connection.remoteAddress);
  console.log('req.socket.remoteAddress', (req.socket && req.socket.remoteAddress));
  console.log('req.socket.socket.remoteAddress', (req.socket.socket && req.socket.socket.remoteAddress));

到目前为止,所有内容都会打印undefined127.0.0.1。这意味着我需要以某种方式配置ngrok。

1 个答案:

答案 0 :(得分:2)

不幸的是,Node.JS中的所有标头名称都是小写的。使用

themes-v21.xml

代替

Theme.MaterialComponents