Referer#
The module is used to block access to a site for requests with invalid values in the "Referer" header field. It should be kept in mind that fabricating a request with an appropriate "Referer" field value is quite easy, and so the intended purpose of this module is not to block such requests thoroughly but to block the mass flow of requests sent by regular browsers. It should also be taken into consideration that regular browsers may not send the "Referer" field even for valid requests.
Configuration Example#
valid_referers none blocked server_names
*.example.com example.* www.example.org/galleries/
~\.google\.;
if ($invalid_referer) {
return 403;
}
Directives#
referer_hash_bucket_size#
Sets the bucket size for the valid referers hash tables. The details of setting up hash tables are provided in a separate document.
referer_hash_max_size#
Sets the maximum size of the valid referers hash tables. The details of setting up hash tables are provided in a separate document.
valid_referers#
|
|
Default |
— |
server, location |
Specifies the "Referer" request header field values that will cause the built-in $invalid_referer variable to be set to an empty string. Otherwise, the variable will be set to "1". Search for a match is case-insensitive.
Parameters can be as follows:
|
the "Referer" field is missing in the request header; |
|
the "Referer" field is present in the request header, but its value has been deleted by a firewall or proxy server; such values are strings that do not start with "http://" or "https://"; |
|
the "Referer" request header field contains one of the server names; |
|
defines a server name and an optional URI prefix. A server name can have an "*" at the beginning or end. During the checking, the server's port in the "Referer" field is ignored; |
|
the first symbol should be a "~". It should be noted that an expression will be matched against the text starting after the "http://" or "https://". |
Example:
valid_referers none blocked server_names
*.example.com example.* www.example.org/galleries/
~\.google\.;
Built-in Variables#
$invalid_referer
#
Empty string, if the "Referer" request header field value is considered valid, otherwise "1".