阿里 SLB +nginx 基于$http_x_forwarded_for 代理IP 访问控制

nginx location 配置

location ~* /admin/login {
#set $my_ip '';
#if ( $http_x_forwarded_for !=client ip){set $my_ip 1;}
#if ( $http_x_forwarded_for != client ip ){ set $my_ip 1;}
#if ( $my_ip = 1) {
# return 302;
#}
#if ($http_x_forwarded_for != "ip1" ) {  
#return 302;
#proxy_pass http://127.0.0.1:8080;
# }
if ( $http_x_forwarded_for !~ "ip1|ip2" ) {  #不在ip1和ip2 允许列表中的 直接return 404  如果没有SLB 直接是 $remote_addr
return 404;
}

proxy_pass http://127.0.0.1:8080; #允许的直接通过代理到后端

}

posted @ 2017-06-22 19:37  robotor  阅读(2648)  评论(0编辑  收藏  举报