Nginx limit_rate到除本地主机IP

时间:2016-07-13 22:21:47

标签: nginx localhost limit

所以在Nginx中,我的位置配置允许MP4流如下,但我想限制所有流量的速率,除了我指定的那些特定的localhost IP。

所以我不希望传输限制的IP地址如下:

172.16.0.1
172.16.0.2
172.16.0.3
172.16.0.4
172.16.0.5
172.16.0.6
etc etc

MP4流的Nginx配置:

location ~ \.mp4$ {
mp4;

limit_rate_after 1m;
limit_rate 1m;

root '//172.16.0.1/Storage1/server/domain/public_www';

expires max;

valid_referers none blocked domain.com *.domain.com;
if ($invalid_referer) {
return   403;
}

}

所以是的任何帮助我应该做的配置调整或更改/做什么只允许我的localhost IP接收mp4文件而不受limit_rate配置限制将是伟大的:)

1 个答案:

答案 0 :(得分:1)

在Nginx配置的HTTP块中

geo $remove_rate_limit {
default 0;
172.16.0.0/24 1;
}

在Nginx配置的服务器位置块中

location ~ \.mp4$ {
mp4;

limit_rate_after 1m; #All users will be limited
limit_rate 1m; #All users will be limited

#Order this after the limit_rate to remove the limit for specific IP's
if ($remove_rate_limit) { #If IP matches
limit_rate_after 0; #Make 0 what is default setting for no limit.
limit_rate 0; #Make 0 what is default setting for no limit.
}

root '//172.16.0.1/Storage1/server/domain/public_www';

expires max;

valid_referers none blocked domain.com *.domain.com;
if ($invalid_referer) {
return   403;
}

}