Browse Source

update commit

edc202104 1 year ago
parent
commit
35930c3ac6
1 changed files with 43 additions and 0 deletions
  1. 43 0
      getIp2.txt

+ 43 - 0
getIp2.txt

@@ -0,0 +1,43 @@
+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为扩展目录名。路径配置必需要准确