Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx - How do I know when $http_referer is not set or empty?

How do I know when the nginx variable $http_referer is not 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!

like image 427
claudiut Avatar asked May 03 '11 09:05

claudiut


2 Answers

http://nginx.org/en/docs/http/ngx_http_referer_module.html#valid_referers

valid_referers server_names ~.;
if ($invalid_referer) {
    return   403;
}
like image 67
Timofey Stolbov Avatar answered Sep 21 '22 07:09

Timofey Stolbov


How about this?

if ($http_referer ~ /^$/) {
    return 403;
}
like image 24
Eric Johnson Avatar answered Sep 21 '22 07:09

Eric Johnson