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

claudiut picture claudiut · May 3, 2011 · Viewed 22k times · Source

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!

Answer

Timofey Stolbov picture Timofey Stolbov · May 3, 2011

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

valid_referers server_names ~.;
if ($invalid_referer) {
    return   403;
}