lnmp重新编译nginx增加geoip模块

nginx -V 在输出界面看是否有–with-http_geoip_module
没有首先进入lnmp shell目录,进入src 将nginx源码解压
将原先编译参数添加,并加入自己需要的模块

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module  --with-http_realip_module --with-http_geoip_module --with-stream=dynamic --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.6/src/openssl-1.1.1b --with-openssl-opt='enable-weak-ssl-ciphers'

#重命名原来的nginx

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

#把编译完成的复制过去(在源码解压目录)

cp /objs/nginx /usr/local/nginx/sbin/nginx

yum -y install geoip-devel GeoIP数据库会被安装在 /usr/share/GeoIP/GeoIP.dat
开始配置nginx的配置文件

geoip_country /usr/share/GeoIP/GeoIP.dat;
# geoip_city    /usr/share/GeoIP/GeoLiteCity.dat;
# 下面一行根据实际情况编写
map $geoip_country_code $allowed_country {
    default no;
    CN yes;
}

然后在server块里面进行配置:

 if ($allowed_country = no) {
        return 403;
    }

你可能感兴趣的:(技术积累,lnmp,nginx,linux)