i thought this would work but for some reason it skips the auth_basic and always returns 200. Same happens if i swap 200 for a 301 redirect.
If i comment out the return statement it works ok. Ideally i want just an /auth
endpoint that once authenticated it will 301 redirect to another path.
location /auth {
auth_basic_user_file /etc/nginx/.htpasswd;
auth_basic "Secret";
return 200 'hello';
}
Am i missing something ?
many thanks
fLo
return
-directives are executed before most other directives. To solve your problem you need to split this into two locations:
location /auth {
auth_basic_user_file /etc/nginx/.htpasswd;
auth_basic "Secret";
try_files DUMMY @return200;
}
location @return200 {
return 200 'hello';
}
The try_files
-directive is evaluated after auth_basic
. The second location is evaluated only as a result of try_files
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With