在http 模块 增加
geo $remote_addr $ip_whitelist{
default 0; include white_ip.conf; }
在location 模块 增加 (注意if 和($ip)之间有空格)
if ($ip_whitelist = 0){
return 403; }在conf 同级目录 添加white_ip.conf 文件
将白名单ip添加进去 如:183.157.83.10 1;
重启nginx 即可
如果white_ip.conf 没有对应的ip 请求服务器将看到 403 forbidden