最终结果,不搞了,一直报错
nginx: [emerg] module "/usr/local/nginx/modules/ngx_http_geoip2_module.so" is not binary compatible
要不就是编译以后用静态的可执行文件替换/usr/bin/nginx,也是会有其他报错
等后面有需要再弄吧,这里只是做个进度记录
发现一个可以参考的
https://www.cnblogs.com/tinywan/p/6965467.html
sudo -i
apt update -y && apt upgrade
cd /home
apt -y install gcc g++ nginx git autoconf automake make libpcre3-dev zlib1g zlib1g-dev libpcre3-dev libssl-dev
这些包现在不安装也行,后面报错的时候会让你安装的。
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
编译安装libmaxminddb
:
./configure
make
make check
make install
ldconfig
cd /home
git clone https://github.com/leev/ngx_http_geoip2_module
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz && cd nginx-1.18.0/
systemctl stop nginx
编译动态加载模块
./configure --add-dynamic-module=/home/ngx_http_geoip2_module
make && make install
cp /home/nginx-1.18.0/objs/ngx_http_geoip2_module.so '/usr/local/nginx/modules/ngx_http_geoip2_module.so'
配置文件开头加入load_module /usr/local/nginx/modules/ngx_http_geoip2_module.so;
动态加载vim /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
load_module /usr/local/nginx/modules/ngx_http_geoip2_module.so;
events {
worker_connections 768;
# multi_accept on;
}
http {
。
。
。
略
wget https://github.com/PrxyHunter/GeoLite2/releases/download/2022.12.16/GeoLite2-Country.mmdb -P /etc
http {
geoip2 /etc/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_country_code country names en;
}
geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {
$geoip2_data_country_code default=China source=$remote_addr country iso_code;
$geoip2_data_country_name country names en;
$geoip2_data_city_name city names en;
$geoip2_data_province_name subdivisions 0 names en;
$geoip2_data_province_isocode subdivisions 0 iso_code;
$geoip2_continent_code continent code;
}
}
http {
...
geoip2 /etc/maxmind-country.mmdb {
auto_reload 5m;
$geoip2_metadata_country_build metadata build_epoch;
$geoip2_data_country_code default=US source=$variable_with_ip country iso_code;
$geoip2_data_country_name country names en;
}
geoip2 /etc/maxmind-city.mmdb {
$geoip2_data_city_name default=London city names en;
}
....
fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
fastcgi_param CITY_NAME $geoip2_data_city_name;
....
}
stream {
...
geoip2 /etc/maxmind-country.mmdb {
$geoip2_data_country_code default=US source=$remote_addr country iso_code;
}
...
}