How to block bad bots User-Agents in Nginx

To block bots by User-Agent in Nginx, add the following to the server entry of the website. Restart Nginx To block acces to a specific file or folder, use If you are using Apache web server, see How to block Bad Bots (User Agents) using .htaccess or Block User-Agent using Cloudflare Back to Nginx