In Apache I have a bunch of rules to block certain unwanted requests.
# Block libwww-perl/5.805 from attempting to exploit security vulnerabilities
RewriteCond %{HTTP_USER_AGENT} ^libwww\-perl/.+ [NC]
RewriteCond %{QUERY_STRING} .
RewriteRule . - [F,L]
# Block generic Java-based clients
RewriteCond %{HTTP_USER_AGENT} ^Java/1\.6\.0_04 [NC]
RewriteRule . - [F,L]
# Block generic Mozilla clients
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5\.0$ [NC]
RewriteRule . - [F,L]
What is the most efficient way to accomplish the same task in nginx?