lnmp重新编译nginx增加geoip模块

Nginx地理IP模块配置
本文介绍如何为Nginx添加http_geoip_module模块,实现基于地理位置的访问控制。包括编译配置步骤、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;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值