标签:map nginx http_x_forwarded_for
目前,仓库通过allow host的方式来控制访问,但实际上没有启到作用,请求从lb过来,host已经变化,所以需要用http_x_forwarded_for来做限制。
19.29.55.15 13.56.217.135 211.22.42.100 119.9.14.149*其他都403*
不升级的情况下不影响
1、map(用于http段) 2、location if else来判断(server)
map $http_x_forwarded_for $access { default false; 123.56.27.15 true; 123.103.7.29 true; 101.21.57.187 true; 221.12.42.100 true; 116.7.37.5 true; 10.150.189.186 true; 41.29.245.18 true; }if ( $access = ‘false‘) { return 403; }
set $access false;
if ( $http_x_forwarded_for = ‘123.56.27.135‘ ) {
set $access true;
}
if ( $http_x_forwarded_for = ‘119.29.144.149‘ ) {
set $access true;
}
if ( $http_x_forwarded_for = ‘119.29.55.135‘ ) {
set $access true;
}
if ( $http_x_forwarded_for = ‘221.122.42.100‘ ) {
set $access true;
}
if ( $access = ‘false‘) {
return 403;
}
本文出自 “一步一步做技术” 博客,请务必保留此出处http://mersap.blog.51cto.com/6495114/1883889
nginx访问控制:如何通过map来控制http_x_forwarded_for访问限制
标签:map nginx http_x_forwarded_for
原文地址:http://mersap.blog.51cto.com/6495114/1883889