Nginx通过客户端IP重定向

时间:2016-03-24 15:51:57

标签: redirect nginx ip

如果他的IP包含在我的特殊数据库中,我想将客户端重定向到特殊页面。

我在ip_addresses.csv中的数据库如: 191.11.23.3 3.4.11.22 5.117.33.4

如何通过nginx.conf来完成?

1 个答案:

答案 0 :(得分:1)

我认为您应该将数据库合并到nginx.conf(我不知道如何在nginx中轻松使用CSV)。

您可以使用geo module。首先,未经测试的例子:

geo $redirectip {
  default 0;
  # you can use "include" of course, see examples in documentation
  192.11.23.3 1;
  3.4.11.22 1;
  5.117.33.4 1;
  ...
}

server {
  if ($redirectip) {
    return/rewrite/whatever_you_want...;
  }
}
相关问题