Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to figure out how to whitelist a user agent from my nginx conf. All other agents should be shown a password prompt.

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.

share|improve this question
1  
nginx.2469901.n2.nabble.com/… –  quanta Dec 1 '12 at 9:38

1 Answer 1

up vote 0 down vote accepted

You can use the auth_request module to achieve this.

Example at http://nginx.2469901.n2.nabble.com/Is-there-a-method-to-allow-a-particular-user-agent-access-to-a-server-rule-that-uses-the-access-and--td6752995.html as per the comment by @quanta.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.