How can I whitelist a user-agent in nginx?
Posted
by
djb
on Server Fault
See other posts from Server Fault
or by djb
Published on 2012-11-29T16:53:01Z
Indexed on
2012/11/29
17:06 UTC
Read the original article
Hit count: 257
nginx
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.
© Server Fault or respective owner