Nginx HTTP basic auth – allowing IP or password-based access

nginx uses similar syntax to that of Apache to allow users to access a directory, depending if their IP or username/pass matches (i.e. you want all users to present a valid username/pass match, but want to let some automated checks coming from specified IPs through, i.e. from ldirectord or nagios). Here is an example to use both HTTP basic auth and IP based auth.

location / {
index index.php;
satisfy any;
auth_basic " intra";
auth_basic_user_file /etc/nginx/htpasswd/;

You can create/modify the auth_basic_user_file with htpasswd program (typically found in apache2-utils or apache-base package, depending on the distribution):

htpasswd /etc/nginx/htpasswd/ someusername