我想在我的流星应用程序中的服务器端获取用户IP地址,以便我可以用一堆东西记录IP地址(例如:订阅邮件列表的非注册用户,或者只是做任何事情)重要的).
我知道,当涉及反向代理时,服务器“看到”的 IP 地址可能与真实源地址不同。在这种情况下,X-Forwarded-For
应解析标头以获取用户的真实公共 IP 地址。注意解析X-Forwarded-For
不应该是自动的(参见http://www.openinfo.co.uk/apache/index.html http://www.openinfo.co.uk/apache/index.html来讨论潜在的安全问题)。
外部参考:这个问题出现在2012年8月的meteor-talk邮件列表 https://groups.google.com/forum/?fromgroups=#!msg/meteor-talk/ebv8U3par_c/(没有提供解决方案)。
1 - 没有 http 请求,在函数中您应该能够通过以下方式获取 clientIP:
clientIP = this.connection.clientAddress;
//EX: you declare a submitForm function with Meteor.methods and
//you call it from the client with Meteor.call().
//In submitForm function you will have access to the client address as above
2 - 通过 http 请求并使用iron-router 及其 Router.map 函数:
在目标路由的操作函数中使用:
clientIp = this.request.connection.remoteAddress;
3 - 使用 Meteor.onConnection 函数:
Meteor.onConnection(function(conn) {
console.log(conn.clientAddress);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)