We want our entire server to be protected from anonymous access except for one endpoint /public
. However we are seeing the location /ping
accessed anonymously with status 200.
Why?
Surely we do not need to put authentication directives on each location block?
server {
location /ping {
return 200 'OK'; # Should not be available anonymously!
}
location = /public {
auth_basic off;
return 200 'OK'; # Should be available anonymously
}
# Users must authenticate in general
satisfy any;
auth_basic "Authentication";
auth_basic_user_file /etc/my/.htpasswd;
}
According to the docs this should work:
Alternatively, you you can limit access to the whole website with basic authentication but still make some website areas public. In this case, specify the off parameter of the auth_basic directive that cancels inheritance from upper configuration levels:
server {
...
auth_basic "Administrator’s Area";
auth_basic_user_file conf/htpasswd;
location /public/ {
auth_basic off;
}
}