I'm using nginx version 1.8 on a centos 6.7 server but when using nginx -V command , I can't see geoip_module there . How can I add it to nginx ?
-
sorry for the external link, but I think you can use this http://nginx.org/en/docs/http/ngx_http_geoip_module.html – c4f4t0r Nov 26 '15 at 19:15
-
thanks but nothing about adding the module to nginx there – movi ran Nov 26 '15 at 19:30
-
This module is not built by default, it should be enabled with the --with-http_geoip_module configuration parameter. http://piwik.org/faq/how-to/faq_166/ – c4f4t0r Nov 26 '15 at 19:33
-
Where did you get nginx from? – Michael Hampton Nov 27 '15 at 08:50
2 Answers
Nginx doesn't have "modules" in apache sense, it has to be recompiled with the module you need included during ./configure.
It's actually pretty easy - just follow this steps:
Install prerequisites for building nginx by using the following commands:
yum group install "Development Tools"
yum install gcc gd-devel GeoIP-devel
Download latest nginx source from http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.15.7.tar.gz
Unpack it & enter the source tree directory
tar xzfv nginx-1.15.7.tar.gz && cd nginx-1.15.7
Get the configuration arguments of your installed nginx (by running
nginx -V
), add the--with-http_geoip_module
option to them or just configure with the following command:./configure --with-http_gzip_static_module --with-pcre --with-file-aio --without-http_scgi_module --without-http_uwsgi_module --without-http_fastcgi_module --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_image_filter_module --with-cc-opt="-march=native -mtune=native -O2 -pipe" --with-sha1-asm --with-zlib-asm=pentiumpro --with-md5-asm --with-pcre-jit --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-http_geoip_module
make && make install
Now you have the GeoIP support in your nginx. To use it, download and unpack databases from http://dev.maxmind.com/geoip/legacy/geolite/
curl http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz | gzip -d - > /etc/nginx/GeoIP.dat
curl http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz | gzip -d - > /etc/nginx/GeoLiteCity.dat
Add them to the http section of your nginx config file:
geoip_country /etc/nginx/GeoIP.dat;
geoip_city /etc/nginx/GeoLiteCity.dat;
And finally define headers, which will contain the GeoIP information in the server section of your nginx config file:
proxy_set_header GEOIP_REGION $geoip_region;
proxy_set_header GEOIP_REGION_NAME $geoip_region_name;
proxy_set_header GEOIP_CITY $geoip_city;
proxy_set_header GEOIP_AREA_CODE $geoip_area_code;
proxy_set_header GEOIP_LATITUDE $geoip_latitude;
proxy_set_header GEOIP_LONGITUDE $geoip_longitude;
proxy_set_header GEOIP_POSTAL_CODE $geoip_postal_code;

- 3,677
- 18
- 23
-
If nginx is already installed and running and one follows your steps above, does this simply overwrite existing install? Config losses? – Chris Apr 07 '19 at 03:43
-
@Chris nope, it only overwrites nginx binariesm. Make sure you use exact configuration directives from your system in step 4 though – Anubioz Apr 09 '19 at 09:07
- create a new file , /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
if your system version is centos 7.x ,you need change it in the 'baseurl'
- then ,
yum install nginx-module-geoip
you got it

- 11
- 1