4

I have installed nginx 1.6 and I want to know how to read an authorization request header from nginx.

If the authorization header is present, then I need to forward to success page success.html.

If authorization header it is not present in the request, then I need to forward to error.html.

How can we do this in nginx?

1 Answer 1

3

how about to catch 401 header:

location @checkauth {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
}

location / {
if ($http_authorization = "") {
#return custom code 
error_page 490 = @checkauth;
return 490;
}
auth_basic "Restricted";
auth_basic_user_file htpasswd;
error_page 401 = @rewrite;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .