Nginx – Block empty user-agents nginx

blockingnginx

My site was under attack and I noticed all the user agents are blank. How can I block this with my nginx?

Screenshot of Log File

I have no idea what to block, if this is an empty user agent or what.

Best Answer

If you want to block blank user agents by sending them a "403" or access denied message then this should work:

if ($http_user_agent = "") { return 403; }

Modifying this to do other things should be straightforward.