我在modulus.io上托管了https Meteor网络应用程序。遵循建议here我有一个服务器方法:
Meteor.methods({
printIP: function() {
return this.connection.clientAddress;
}
});
我在实时网站上的浏览器控制台中调用此方法:
Meteor.call('printIP', function(err, ip) { console.log(ip); })
但这总是会返回Modulus的load balancer的IP地址,54.236.216.66。
如何访问客户端的IP地址而不是负载均衡器?
谢谢!
答案 0 :(得分: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;
}
}
});