我试图实现时间和地理位置的限制,我们的CMS。下面是当前设置的样子
这种要求是,在一段时间内,来自特定国家的流量不能访问特定的URL /类别,但来自世界其他地区的流量可以不受任何限制地访问相同的URL /类别。
地理位置部分似乎并不令人望而生畏,但我一直未能找到任何关于限制流量的时间。
当然,我可以设置两种清漆或nginx配置,一种是没有限制的,一种是cron作业,根据我想要做的事情来替换物理文件,但我希望有一个更干净的解决方案。
我知道所有这些都可以用PHP来处理,但我不能从堆栈中移除Varnish,我需要放入5-6台服务器来处理负载,这会增加我无法证明的成本。
帮助?
发布于 2018-04-26 08:57:11
您可以在清漆中使用now,并在清漆日期上做一个regex以生成403或其他任何东西。
下面是一个关于如何使用varnishtest的示例now案例
varnishtest "Time Gate"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import std;
sub vcl_recv {
//now is in RFC format: Thu, 26 Apr 2018 08:40:22 GMT
//set it in a "ghost header" to convert it to a STRING otherwise it is a TIME
// and regex won't work
set req.http.now_string = now;
//Check the hour
if(req.http.now_string ~ "^.* [0-9]{4} 08") {
// Do stuff when its 08:xx
} else {
// Otherwise do something else.
}
}
sub vcl_deliver {
set resp.http.x-forwarded-for = client.ip;
set resp.http.now_string = req.http.now_string;
}
} -start
client c1 {
txreq -url "/1"
rxresp
expect resp.http.now_string ~ "2018"
} -run关于地理保护,你也可以这样做,用https://github.com/varnish/libvmod-geoip清漆,这个vmod。(还没有亲自测试)
https://stackoverflow.com/questions/50021315
复制相似问题