標籤:senginx geoip
一、軟體模組依賴性:
[[email protected]] # yum -y install gcc+ gcc-c++ gcc* make* libpcre.so* openssl* pcre* zlib* libtool* libxml2* libxslt* gd* lua*
二、安裝GeoIP
安裝 MaxMind 的 GeoIP 庫
MaxMind 提供了免費的 IP 地區資料庫(GeoIP.dat),不過這個資料庫檔案是二進位的,需要用 GeoIP 庫來讀取,所以除了要下載 GeoIP.dat 檔案外(見下一步),還需要安裝能讀取這個檔案的庫。
:http://dev.maxmind.com/geoip/legacy/geolite/
(1)編譯安裝GeoIP
[[email protected]] # wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
[[email protected]] # tar -zxvf GeoIP.tar.gz
[[email protected]] # cd GeoIP-1.4.8/
[[email protected]] # ./configure
[[email protected]] # make
[[email protected]] # make install
剛才安裝的庫自動安裝到 /usr/local/lib 下,所以這個目錄需要加到動態連結配置裡面以便運行相關程式的時候能自動綁定到這個 GeoIP 庫:
[[email protected]] # echo ‘/usr/local/lib‘ >> /etc/ld.so.conf
[[email protected]] # ldconfig
(2)下載安裝GeoIP.dat(GeoIP國家資料庫)
MaxMind 提供了免費的 IP 地區資料庫,這個資料庫是二進位的,不能用文字編輯器開啟,需要上面的 GeoIP 庫來讀取:
[[email protected]] # wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
[[email protected]] # gzip -d GeoIP.dat.gz
(3)下載安裝GeoLiteCity.dat(GeoIP城市地區資料庫)
[[email protected]] # http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
[[email protected]] # gzip -d GeoLiteCity.dat.gz
三、編譯安裝SeNginx
(1)下載Nginx版本:
[[email protected] ~]# wget http://senginx.org/download/senginx-1.6.0.tar.gz
(2)編譯安裝SeNginx:
因為要用到 http_geoip_module 模組,系統內建的 nginx 一般不帶這個模組,所以要下載 nginx 原始碼後自行編譯:
[[email protected]] # tar zxvf senginx-1.6.0.tar.gz
[[email protected]] # cd senginx-1.6.0
[[email protected]] # vim se-configure.sh
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_geoip_module \
--with-mail \
--with-mail_ssl_module \
--with-ipv6 \
--with-http_ssl_module \
--with-debug \
[[email protected]] # ./se-configure.sh --prefix=/usr/local/nginx
[[email protected]] # make
[[email protected]] # make install
[[email protected]] # cd /usr/local/
[[email protected]] # nginx/sbin/nginx -V
(3)配置 Nginx
配置nginx,在相關地方加上如下的配置就可以了:
[[email protected]] # vim /usr/local/nginx/conf/nginx.conf
session_max_size 10240;
geo $ip_wl {
ranges;
default 0;
127.0.0.1-127.0.0.1 1;
10.0.101.1-10.0.101.254 1;
}
whitelist_ua $ua_wl {
"autotest" ".*\.test\.com";
}
(4)修改虛擬機器主機設定檔
[[email protected]] # vim /usr/local/nginx/conf/vhosts/server.conf
########## Robot Mitigation ##########
robot_mitigation on;
robot_mitigation_cookie_name enorth_cookie;
robot_mitigation_mode js;
robot_mitigation_blacklist 3;
robot_mitigation_timeout 60;
robot_mitigation_challenge_ajax on;
robot_mitigation_global_whitelist ua_var_name=ua_wl ip_var_name=ip_wl ip_var_value=1;
########## cookie ##########
#cookie_poisoning_action block/pass/remove/blacklist,num;
cookie_poisoning on;
cookie_poisoning_action blacklist,5;
cookie_poisoning_log on;
cookie_poisoning_whitelist ua_var_name=ua_wl ip_var_name=ip_wl ip_var_value=1;
######### naxsi_whitelist ##########
naxsi_whitelist ua_var_name=ua_wl ip_var_name=ip_wl ip_var_value=1;
LearningMode;
SecRulesEnabled;
#SecRulesDisabled;
DeniedUrl "/RequestDenied";
include wl.conf;
## check rules
CheckRule "$XSS >= 4" BLOCK;
CheckRule "$TRAVERSAL >= 4" BLOCK;
CheckRule "$EVADE >= 8" BLOCK;
CheckRule "$UPLOAD >= 8" BLOCK;
CheckRule "$RFI >= 8" BLOCK;
CheckRule "$SQL >= 8" BLOCK;
}
location /RequestDenied {
return 403;
}
#location / {
#if ($geoip_country_code = CN) {
#rewrite ^/$ /cn redirect;
#}
#
#if ($geoip_country_code != CN) {
#rewrite ^/$ /en redirect;
#}
#}