1、安装依赖
sudo apt-get install libmaxminddb0 libmaxminddb-dev
2、下载模块
git clone https://github.com/leev/ngx_http_geoip2_module.git
3、查看nginx已安装模块
nginx -V
示例
configure arguments: --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module-master --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module
4、手动编译 cd /www/server/nginx/src/ 执行以下命令修改配置
./configure --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module-master --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module --add-module=/www/server/ngx_http_geoip2_module
5、解决编译中luajit模块异常,再执行4的命令
export LUAJIT_INC=/usr/local/include/luajit-2.1
export LUAJIT_LIB=/usr/local/lib
6、第4成功后,开始编译
make && make install
7、重启nginx
8、下载Country.mmdb库到服务器/www/server/Country.mmdb,在nginx中http模块配置
geoip2 /www/server/Country.mmdb {
auto_reload 5m ;
$geoip2_country_code country iso_code;
}
map $geoip2_country_code $allowed_country {
default yes;
CN no;
}
9、网站站点service中添加配置
# 匹配国家代码定义为no的,禁止访问,返回403(上面定义中国的 iso_code 为no)
if ( $allowed_country = no ) { return 403; }
宝塔nginx安装geoip2
十二月未完2024-08-08 4:06
相关推荐
绿箭柠檬茶2 天前
Ubuntu 服务器配置转发网络访问风_峰2 天前
Ubuntu Linux SD卡分区操作太空的旅行者3 天前
告别双系统——WSL2+UBUNTU在WIN上畅游LINUX人工智能训练师3 天前
Ubuntu22.04如何安装新版本的Node.js和npmxqlily3 天前
Linux操作系统之Ubuntu风_峰3 天前
Petalinux相关配置——ZYNQ通过eMMC启动风_峰3 天前
【ZYNQ开发篇】Petalinux和电脑端的静态ip地址配置烦躁的大鼻嘎3 天前
【Linux】深入Linux多线程架构与高性能编程破烂儿3 天前
Ubuntu Server 安装图形界面和通过Window远程桌面连接服务器(Xrdp)a.3023 天前
OpenCV(cv2)学习笔记:从模板匹配入门到常用函数