在CentOS 6 的 nginx 上安裝 GeoIP Module 來 Block IP
後來發現在 nginx 1.13 版的時後啟動會出現
QUOTE:
[root@www nginx]# nginx -t
nginx: [emerg] unknown directive "geoip_country" in /etc/nginx/nginx.conf:40
nginx: configuration file /etc/nginx/nginx.conf test failed
查了一下google大神...原來是 nginx 載入是改成 dynamic 的方式
--with-http_geoip_module=dynamic
原本正常安裝套件步驟:
# yum install geoip geoip-devel
現在需要另外安裝一個模組.先新增 nginx 的 repo
# vi /etc/yum.repos.d/nginx.repo
QUOTE:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
然後安裝 nginx-module-geoip 套件:
QUOTE:
# yum install nginx-module-geoip
The GeoIP dynamic module for nginx has been installed.
To enable this module, add the following to /etc/nginx/nginx.conf
and reload nginx:
load_module modules/ngx_http_geoip_module.so;
另外提示訊息說...還需要另外在 nginx.conf 裡面增加一行,需要在最上層載入
# vi /etc/nginx/nginx.conf
QUOTE:
user nginx;
worker_processes 1;
worker_rlimit_nofile 1024;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
#### Load GeoIP Module ####
load_module modules/ngx_http_geoip_module.so;
load_module modules/ngx_stream_geoip_module.so;
event {
..
..
}
http {
..
..
}
重啟之後...原本的設定檔都不用變...就可以正常啟動nginx 並且限制區域瀏覽了~