Setting a header inside an if block

Gena Makhomed gmm at csdoc.com
Wed Feb 5 18:37:46 UTC 2014


On 05.02.2014 19:31, justink101 wrote:

> I currently have:
>
> server{
>      ...
>      if ($remote_user = "") {
>          return 401;
>      }
>      ...
> }
>
> But what I really want is:
>
> server{
>      ...
>      if ($remote_user = "") {
>          add_header WWW-Authenticate 'Basic realm="mydomainhere.com"';
>          return 401;
>      }
>      ...
> }
>
> But nginx won't allow me to use the add_header directive inside an if block.
> How can I achieve this?

via http://nginx.org/en/docs/http/ngx_http_auth_request_module.html

-- 
Best regards,
  Gena



More information about the nginx mailing list