nginx访问控制:如何通过map来控制http_x_forwarded_for访问限制

通过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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值