checking headers

Robert Paprocki rpaprocki at fearnothingproductions.net
Mon May 30 18:19:29 UTC 2016


On Sat, May 28, 2016 at 12:48 PM, Larry Martell <larry.martell at gmail.com>
wrote:

> Is there any way with nginx to check a request's headers and send back
> a 401 if the headers are not proper?
>


Yes, you can do with this via the 'map' and 'if' directives. A trivial
example:

http {
        # if the "X-Foo" request header contains the phrase 'data', set
$bar to 1; otherwise, set it to 0
        map $http_x_foo $bar {
                default 0;
                "~data" 1;
        }

    server {
        location /t {
                if ($bar) {
                        return 401;
                }
        }
}

See also http://nginx.org/en/docs/http/ngx_http_map_module.html and
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20160530/c1c7bdfe/attachment.html>


More information about the nginx mailing list