<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 28, 2016 at 12:48 PM, Larry Martell <span dir="ltr"><<a href="mailto:larry.martell@gmail.com" target="_blank">larry.martell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Is there any way with nginx to check a request's headers and send back<br>
a 401 if the headers are not proper?<br></blockquote><div><br></div><div><br></div><div>Yes, you can do with this via the 'map' and 'if' directives. A trivial example:<br><br>http {</div><div> # if the "X-Foo" request header contains the phrase 'data', set $bar to 1; otherwise, set it to 0<br><div> map $http_x_foo $bar {</div><div> default 0;</div><div> "~data" 1;</div><div> }</div></div><div><br></div><div><div> server {</div><div> location /t {<br></div><div> if ($bar) {</div><div> return 401;</div><div> }</div><div> }<br></div></div><div>}<br></div><div><br></div><div>See also <a href="http://nginx.org/en/docs/http/ngx_http_map_module.html">http://nginx.org/en/docs/http/ngx_http_map_module.html</a> and <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if">http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if</a></div></div></div></div>