Nginx IP 白名单设置

时间:2022-12-07 21:04:28

1:ip.config

192.168.3.15 1;
192.168.3.10 1;
192.168.0.8 1;

2:nginx.conf

#geoIP的白名单
geo $remote_addr $ip_whitelist {
default 0;
include ip.conf;
}

location /console {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#白名单配置
if ( $ip_whitelist = 1 ) {
proxy_pass http://192.168.3.15:9401;
break;
}

return 403;
}