Nginx - How do I know when $http_referer is not set or empty?
How do I know when the nginx variable $http_referer is n开发者_StackOverflow社区ot set or empty?
I receive some requests that don't have a http referer. In nginx logs $http_referer appears like that: "-". What I am trying to do is to "return 403;" if the $http_referer is not set or empty as in this case.
Thanks!
http://nginx.org/en/docs/http/ngx_http_referer_module.html#valid_referers
valid_referers server_names ~.;
if ($invalid_referer) {
return 403;
}
How about this?
if ($http_referer ~ /^$/) {
return 403;
}
It works for me, likes below:
set $flag 0;
if ($http_referer = "-") {
set $flag 1;
}
if ($flag = 1) {
return 403;
}
精彩评论