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.
1 2 3 |
if ($http_user_agent ~ (semrush|opensiteexplorer|ahrefs|seekport|mj12bot)) { return 403; } |
Restart Nginx
1 |
systemctl restart nginx |
To block acces to a specific file or folder, use
1 2 3 |
location /file-to-block.php { return 408; } |
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