2

我有一个托管在modules.io上的 https Meteor webapp 。按照这里的建议,我有一个服务器方法:

Meteor.methods({
    printIP: function() {
        return this.connection.clientAddress;
    }
});

我从实时站点上的浏览器控制台调用它:

Meteor.call('printIP', function(err, ip) { console.log(ip); })

但这总是返回 Modulus 的负载均衡器的 IP 地址 54.236.216.66。

如何访问客户端的 IP 地址而不是负载均衡器的 IP 地址?

谢谢!

4

1 回答 1

4

通过一些实验,我找到了解决方案:

Meteor.methods({
   printIP: function() {
      if (this.connection.httpHeaders && this.connection.httpHeaders['x-forwarded-for']) {
         return this.connection.httpHeaders['x-forwarded-for'];
      } else {
         return this.connection.clientAddress;
      }
   }
});
于 2016-01-01T09:03:57.880 回答