当前位置:首页 - Linux

Centos 下安装GeoIP2模块,与libmaxminddb 库

作者:高景洋 日期:2026-04-23 20:18:02 浏览次数:4
一、GeoIP2 模块下载

1、使用wget 或 curl 方式
wget https://github.com/leev/ngx_http_geoip2_module/archive/refs/heads/master.zip
curl -L -o ngx_http_geoip2_module.zip https://github.com/leev/ngx_http_geoip2_module/archive/refs/heads/master.zip

也可以使用git:git clone https://github.com/leev/ngx_http_geoip2_module.git

2、然后解压缩:
unzip ngx_http_geoip2_module.zip

******************************************

二、libmaxminddb 库安装

1. 安装 libmaxminddb 库
libmaxminddb 是 ngx_http_geoip2_module 的依赖库,必须先安装它。

在 CentOS 上安装:
运行以下命令安装 libmaxminddb 和开发工具:
sudo yum install epel-release -y
sudo yum install libmaxminddb libmaxminddb-devel -y

如果系统中没有 libmaxminddb:
你可以手动编译安装:

下载 libmaxminddb 源码:
wget https://github.com/maxmind/libmaxminddb/releases/download/1.7.1/libmaxminddb-1.7.1.tar.gz

解压并进入目录:
tar -zxvf libmaxminddb-1.7.1.tar.gz
cd libmaxminddb-1.7.1

编译并安装:
./configure
make
sudo make install

更新动态链接库:
sudo ldconfig

2. 重新运行 ./configure
安装 libmaxminddb 后,重新运行 Nginx 的 ./configure 命令:
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_geoip_module \
--add-module=/root/soft/ngx_http_geoip2_module-master

*****/root/soft/ngx_http_geoip2_module-master为 GeoIP2 模块下载中解压的路径

3. 编译并安装 Nginx
如果 ./configure 成功,继续运行以下命令:
make
sudo make install

4. 验证安装
检查 Nginx 是否成功加载 geoip2 模块:
nginx -t

如果没有报错,说明模块已成功安装。
本文永久性链接:
<a href="http://r4.com.cn/art241.aspx">Centos 下安装GeoIP2模块,与libmaxminddb 库</a>
当前header:Host: r4.com.cn X-Host1: r4.com.cn X-Host2: r4.com.cn X-Host3: 127.0.0.1:8080 X-Forwarded-For: 10.2.101.141, 216.73.216.200 X-Real-Ip: 216.73.216.200 X-Domain: r4.com.cn X-Request: GET /art241.aspx HTTP/1.1 X-Request-Uri: /art241.aspx Connection: close Accept: */* User-Agent: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com) Accept-Encoding: gzip, br, zstd, deflate Via: 1.1 squid-proxy-5b5d847c96-9xb7n (squid/6.13) Cache-Control: max-age=259200