Nginx下实现IP白名单限制的方式 nginxgeoip whitelistremote_addr
程序员文章站
2022-03-19 16:52:55
...
Nginx下实现IP白名单限制的方式如下:
【1/3】增加指定IP白名单文件
vim /etc/nginx/ip.conf
10.112.8.39 1;
【2/3】修改nginx配置
vim /etc/nginx/nginx.conf
geo $remote_addr $ip_whitelist{
default 0;
include /etc/nginx/ip.conf;
}
【3/3】为匹配项做白名单设置
vim /etc/nginx/conf.d/port8081.conf
location /yourcontexturi {
if ( $ip_whitelist = 0 ){
return 403;
}
root /home/can_do/application/;
#proxy_redirect default;
proxy_connect_timeout 90;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
【1/3】增加指定IP白名单文件
vim /etc/nginx/ip.conf
10.112.8.39 1;
【2/3】修改nginx配置
vim /etc/nginx/nginx.conf
geo $remote_addr $ip_whitelist{
default 0;
include /etc/nginx/ip.conf;
}
【3/3】为匹配项做白名单设置
vim /etc/nginx/conf.d/port8081.conf
location /yourcontexturi {
if ( $ip_whitelist = 0 ){
return 403;
}
root /home/can_do/application/;
#proxy_redirect default;
proxy_connect_timeout 90;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
下一篇: 轻量级 js2java RPC 框架发布