auth_basic within location block doesn't work when return is specified?
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
.