Allow only one User-Agent, block the rest in nginx?

nginx

Solution

Try this:

if ($http_user_agent !~* (A-certain-self-made-User-Agent-here)) {
        return 403;
}

This should be a 'not match' on your certain user agent. Reference info here: HttpRewriteModule

Problem

new to this site so i'll keep it brief: I have currently: ``` if ($http_user_agent ~* (A-certain-self-made-User-Agent-here)) { return 200; } ``` Which works very well. (Tested by switching 200 to 403). My question is: Is there a way in: /etc/nginx/sites-enabled/default to make it allow only ONE User-Agent and deny the rest? I know this seems stupid, but it's something i'd like to have done, (if possible). Like maybe this?: ``` if (http_user_agent ~*(user-agent)) { return 200; else return 403; } ```

Original source