通过map修改访问限制
目前,仓库通过allow host的方式来控制访问,但实际上没有启到作用,请求从lb过来,host已经变化,所以需要用http_x_forwarded_for来做限制。
允许访问ip
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:
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;
}
location:
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;
}
时间: 2024-10-10 00:31:07