In 2020, use the latest NGINX ngx_http_geoip2 module to block IPs by country or region
In 2020, the latest NGINX ngx_http_geoip2 module can precisely block IP access by country or region Install GeoIP2 on CentOS 7 and route requests by IP country in nginx Install geoip2 lib cd /usr/local/src rm -f libmaxminddb-1.4.2.tar.gz wget https://github.com/maxmind/libmaxminddb/releases/download/1.4.2/libmaxminddb-1.4.2.tar.gz tar -xzf libmaxminddb-1.4.2.tar.gz cd libmaxminddb-1.4.2 yum install gcc gcc-c++ make -y ./configure make make check sudo make install echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf sudo ldconfig Download ngx_http_geoip2_module cd /usr/local/src wget https://github.com/leev/ngx_http_geoip2_module/archive/3.3.tar.gz tar -xzf 3.3.tar.gz mv ngx_http_geoip2_module-3.3 ngx_http_geoip2_module # nginx集成 cd /usr/local/src wget http://nginx.org/download/nginx-1.16.1.tar.gz tar -zxf nginx-1.16.1.tar.gz cd nginx-1.16.1 useradd -M -s /sbin/nologin www yum install gcc gcc-c++ make pcre-devel zlib-devel openssl-devel -y ./configure --user=www --group=www --prefix=/usr/local/nginx \ --with-ld-opt="-Wl,-rpath -Wl,/usr/local/lib" \ --with-http_sub_module \ --with-http_realip_module \ --with-http_gzip_static_module \ --with-http_ssl_module \ --with-http_v2_module \ --add-module=/usr/local/src/ngx_http_geoip2_module make make install Download geoip2 IP database The latest GeoLite2-City.mmdb for 2020 cannot be downloaded directly. You must register a maxmind account.