Basic authentication for everyone except localhost in nginx

Revision history
Tags: nginx

Introduction

I have a shop order system where some admin pages are password protected using HTTP Basic Auth in nginx. Now I want to have a monitoring daemon accessing the admin pages without it having to authenticate itself.

location /admin {
  satisfy any;

  allow 127.0.0.1;
  deny  all;

  auth_basic "r u l33t f00di3?";
  auth_basic_user_file /srv/foodshop-tesoro/.htpasswd;
}

The clue here is the satisfy directive, which can be either all or any. Setting any in this case forces the request to either stem from localhost, or to be authenticated using auth_basic.

References

If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.