【问题标题】:Redirecting viewers to other site based on country geoip根据国家/地区 geoip 将查看者重定向到其他站点
【发布时间】:2014-11-26 02:35:12
【问题描述】:

假设我有一个网站 (www.abc.com/featured/abc) 并希望将(仅该链接)从马来西亚以外的其他国家/地区的观众重定向到 youtube 视频。但是 www.abc.com 仍然是全球性的.是的,我的服务器已经在使用 geoip 模块进行编译。

这是我在 etc/nginx/sites-available/abc.com 中所做的

location featured/abc/ {
  if ($geoip_country_code != "MY") {
    rewrite ^ https://www.youtube.com/watch?v=MaMuQPmzrrU;
  }
}

但它仍然无法正常工作。我在代码中做错了什么

【问题讨论】:

    标签: nginx geoip


    【解决方案1】:

    尝试这样的映射变量:

    http {
    ...
    map $geoip_country_code $georedirect {
      default 0;
      MY 1;
    }
    ...
    }
    
    server {
    ...
    location /featured/abc/ {
      if ($georedirect) {
        return 301 https://www.youtube.com/watch?v=MaMuQPmzrrU;
      }
    }
    ...
    }
    

    更多信息: Module ngx_http_map_module

    【讨论】:

    • 这真的有效吗?在有很多用户的网站上呢?
    猜你喜欢
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 2013-11-08
    • 2019-04-15
    • 1970-01-01
    • 2019-09-26
    相关资源
    最近更新 更多