Home > ngx_http_referer_host_module

ngx_http_referer_host_module

Ngx_http_referer_host_module is a project mainly written in C, based on the View license.

adds $referer_host to the nginx.conf

NAME ngx_http_referer_host_module - implements $referer_host variable

SYNOPSIS http {

    map $referer_host $valid {
    default          0;
    example.com      1;
    www.example.com  1;
    }

    map $referer_host $invalid {
    hostnames;
    default          1;
    .example.com     0;
    }

    ...

    server {

    location / {
        if ($invalid) {
        return 403;
        }
    }

    ...
    }
}

DESCRIPTION A very simple module that parses http referer header and exports resulting hostname into $referer_host variable to use in nginx.conf.

And just in case modifies referer header making its hostname part
lower-cased.

You can achieve something like this in nginx 0.9.6+ with map and pcre:

map $http_referer $referer_host {
    default "";
    ~^https?://(?<H>[^:/]+) $H;
}

INSTALLATION As usual for nginx modules:

./configure --add-module=/path/to/ngx_http_referer_host_module ... 
make
make install

AUTHOR Alexandr Gomoliako [email protected]

LICENSE Copyright 2011 Alexandr Gomoliako. All rights reserved.

This module is free software. It may be used, redistributed and/or 
modified under the terms described in LICENSE file.
Previous:pkRedirectPlugin