Redirecting viewers to other site based on country geoip

梦想的初衷 提交于 2019-12-12 19:26:28

问题


let's say I have a website (www.abc.com/featured/abc) and wanted to redirecting (only that link) the viewer from other country except Malaysia to youtube video.. But www.abc.com is still worldwide. And yes, my server is already compiling with geoip module.

here is what i did in etc/nginx/sites-available/abc.com

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

but it still not working. Do I did somewhere wrong in the code


回答1:


Try map variable like this:

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;
  }
}
...
}

More info: Module ngx_http_map_module



来源:https://stackoverflow.com/questions/27140418/redirecting-viewers-to-other-site-based-on-country-geoip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!