How can I enable HTTP Basic Auth for everything except for a certain file?
Here is my current server block configuration for the location:
locat
I am doing something similar using "map" instead of "if" to assign the auth_basic realm variable and htpasswd file:
map $http_host $siteenv {
default dev;
~^(?.+)\.dev dev;
~^(?.+)\.devprofile devprofile;
~^(?.+)\.devdebug devdebug;
~^(?.+)\.test test;
~^(?.+)\.demo demo;
~^(?.+)\.stage stage;
# Live
~^(?.+)\.live live;
~^.*\.(?P.+)\.[a-zA-Z]* live;
}
map $http_host $auth_type {
default "Restricted";
~^(?.+)\.dev "Development";
~^(?.+)\.devprofile "Development";
~^(?.+)\.devdebug "Development";
~^(?.+)\.test "Testing";
~^(?.+)\.stage "Stage";
~^(?.+)\.demo "Demo";
# Live
~^(?.+)\.live "off";
~^.*\.(?P.+)\.[a-zA-Z]* "off";
}
server {
.. etc ..
auth_basic $auth_type;
auth_basic_user_file /etc/nginx/conf.d/htpasswd-$siteenv;
}