宝塔nginx安装geoip2

复制代码
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; }
相关推荐
Nie_Xun23 分钟前
Ubuntu 安装与 NVIDIA 显卡驱动配置 2篇
linux·运维·ubuntu
HIT_Weston27 分钟前
25、【Ubuntu】【远程开发】内网穿透:密钥算法介绍(一)
linux·运维·tcp/ip·ubuntu
Arvin6272 小时前
Ubuntu 22.04 Docker 安装指南
linux·ubuntu·docker
赴遥4 小时前
[出现错误 2147942402 (0x80070002) (启动“ubuntu2004.exe”时)]
ubuntu·win11·wsl2
一直向钱6 小时前
Ubuntu 服务器的无法使用WinSCP低版本连接登录
linux·服务器·ubuntu
山川而川-R7 小时前
ubuntu摄像头型号匹配不上_11-6
linux·windows·ubuntu
人工智能训练17 小时前
如何在 Ubuntu 22.04 中安装 Docker 引擎和 Linux 版 Docker Desktop 桌面软件
linux·运维·服务器·数据库·ubuntu·docker·ai编程
三五度1 天前
vmware的ubuntu20.04无网络图标
linux·ubuntu
QT 小鲜肉1 天前
【个人成长笔记】将Try Ubuntu里面配置好的文件系统克隆在U盘上(创建一个带有持久化功能的Ubuntu Live USB系统)
linux·开发语言·数据库·笔记·ubuntu
春风霓裳1 天前
ubuntu磁盘管理、磁盘扩容
linux·运维·ubuntu