12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 1、宝塔编译安装nginx
- 2、终端运行
- 安装IP数据库支持
- yum install libmaxminddb-devel -y
-
- 下载Nginx扩展
- git clone https://github.com/leev/ngx_http_geoip2_module.git
- 或(此库包含国家数据IP库)
- git clone https://always77.xyz/always/geoIp2.git
-
- 修改nginx安装文件或用编辑工作打开
- vi /www/server/panel/install/nginx.sh
-
- 搜索:./configure 找到编译安装启动位置
- 插入:--add-module=/root/ngx_http_geoip2_module
-
- 3、重新执行编译安装(版本号需跟初始安装一致)
- sh /www/server/panel/install/nginx.sh install 1.22
- 4、登陆宝塔修改nginx配置
- 在http节点下增加配置项
-
- # 引入IP数据库
- geoip2 /root/ngx_http_geoip2_module/Country.mmdb {
- $geoip2_data_country_code country iso_code;
- }
-
- # 映射 默认值yes 中国禁止(其它根据情况配置)
- map $geoip2_data_country_code $allowed_country {
- default yes;
- CN no;
- }
- 5、修改站点配置
- 在server节点下
-
- if ($allowed_country = no){
- return 403;
- }
-
- 注:ngx_http_geoip2_module为扩展目录名。路径配置必需要准确
|