How can I whitelist a user-agent in nginx?
- by djb
I'm trying to figure out how to whitelist a user agent from my nginx conf. All other agents should be shown a password.
In my naivity, I tried to put the following in before deny all:
if ($http_user_agent ~* SpecialAgent ) { allow; }
but I'm told "allow" directive is not allowed here (!).
How can I make it work?
A chunk of my config file:
server {
server_name site.com;
root /var/www/site;
auth_basic "Restricted";
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
allow 123.456.789.123;
deny all;
satisfy any;
#other stuff...
}
Thanks for any help.