In the main server block (e.g. /etc/nginx/nginx.conf) add the following:

        if ($http_user_agent ~* (AgentName) ) {
        return 403;
        }

Test nginx config and restart:

nginx -t
service nginx restart

To test the agent gets blocked:

curl -I -H 'User-agent: AgentName' localhost/bla

HTTP/1.1 403 Forbidden
Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@linuxtutorial.co.uk.