我有一个网站是针对国外访问的,需要屏蔽国内访问。通过调用一个ip数据库来判断是否是国内用户访问,国内用户访问的话就执行403.
我编译了geoip后,在nginx的http模块加入了以下代码:
- geoip2 /usr/share/GeoIP/Country.mmdb {
- $geoip2_data_country_code country iso_code;
- }
- map $geoip2_data_country_code $allowed_country {
- default yes;
- CN no;
- }
复制代码 然后在网站配置文件加入了以下代码:
- error_page 403 /403.html;
- if ($allowed_country = no) {
- return 403;
- }
复制代码 并在网站根目录增加了403.html文件,写入了一些东西,但是页面没有调用到403.html。
|
|