根据地区过滤访问
在宝塔中选择编译安装,添加--add-module=目录/ngx_http_geoip2_module


nginx配置修改
bash
#加载
load_module modules/ngx_http_geoip2_module.so;
load_module modules/ngx_stream_geoip2_module.so; #需要四层限流时再加
#允许访问区域
map $geoip2_country_code $allowed { default 0; CN 1; HK 1; MO 1; TW 1; }
伪静态中配置
bash
if ($allowed = no)
{
return 403;
}
跳转部分
bash
if ($host = "qhzhiye.cn"){
rewrite ^/(.*)$scheme://www.qhzhiye.cn/$1 permanent;
}
完整伪静态
bash
location ~* (runtime|application)/{
return 403;
}
location / {
if ($allowed = no)
{
return 403;
}
if ($host = "qhzhiye.cn"){
rewrite ^/(.*)$scheme://www.qhzhiye.cn/$1 permanent;
}
if (!-e $request_filename){
rewrite ^(.*)/𝑖𝑛𝑑𝑒𝑥.𝑝ℎ𝑝?𝑠=1 last; break;
}
}