The error message you're encountering is straightforward - Nginx's GeoIP module requires the underlying GeoIP library to be installed on your system before compilation. This is a common dependency issue when compiling Nginx with additional modules.
For Ubuntu/Debian systems, you'll need to install:
sudo apt-get install libgeoip-dev geoip-database
For CentOS/RHEL systems:
sudo yum install GeoIP-devel
Here's a full example of compiling Nginx with GeoIP support:
# Install dependencies
sudo apt-get update
sudo apt-get install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libgeoip-dev
# Download and extract Nginx
wget http://nginx.org/download/nginx-1.23.3.tar.gz
tar -xzvf nginx-1.23.3.tar.gz
cd nginx-1.23.3
# Configure with GeoIP module
./configure --with-http_geoip_module \
--with-stream_geoip_module \
--with-http_ssl_module
# Compile and install
make
sudo make install
After installation, verify GeoIP is working with this Nginx configuration example:
http {
geoip_country /usr/share/GeoIP/GeoIP.dat;
geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
server {
location /myip {
return 200 "$remote_addr $geoip_country_code $geoip_city";
}
}
}
If you still encounter issues:
- Verify library paths:
ldconfig -p | grep GeoIP
- Check for database files in
/usr/share/GeoIP/
- Ensure you're using compatible versions of Nginx and GeoIP
For those preferring pre-built packages:
# Ubuntu/Debian
sudo apt-get install nginx-extras
# CentOS/RHEL
sudo yum install nginx-module-geoip
Remember to load the module in nginx.conf:
load_module modules/ngx_http_geoip_module.so;
The error message clearly indicates that Nginx's GeoIP module requires the underlying GeoIP library to be installed on your system before compilation. This is a common dependency issue when building Nginx from source with optional modules.
You'll need both the GeoIP C library and its development headers. On Debian/Ubuntu systems, these are separate packages:
sudo apt-get install libgeoip1 libgeoip-dev
For RedHat/CentOS systems:
sudo yum install GeoIP GeoIP-devel
Here's a full example of compiling Nginx with GeoIP support after installing dependencies:
# Download latest Nginx source
wget http://nginx.org/download/nginx-1.23.3.tar.gz
tar -zxvf nginx-1.23.3.tar.gz
cd nginx-1.23.3
# Configure with GeoIP module
./configure --with-http_geoip_module \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock
# Compile and install
make
sudo make install
After installation, verify that the GeoIP module is properly loaded:
nginx -V 2>&1 | grep -o with-http_geoip_module
You should see with-http_geoip_module
in the output if successful.
If you're using Nginx 1.9.11+, you can compile GeoIP as a dynamic module:
./configure --with-compat --with-http_geoip_module=dynamic
make
sudo make install
Then load it in your nginx.conf:
load_module modules/ngx_http_geoip_module.so;
- Ensure you have build-essential or equivalent installed
- Check that the GeoIP library paths are in your linker's search path
- Verify package versions are compatible
- Consider using MaxMind's libmaxminddb as an alternative