Setting a header inside an if block

justink101 nginx-forum at nginx.us
Wed Feb 5 17:31:32 UTC 2014


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?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,247218,247218#msg-247218



More information about the nginx mailing list