Set up the bad bot blocker using NGinx
published on
If you haven't yet set up NGinx you can do so by following Install the latest version of NGinx, pagespeed and other modules.
Setting up the bad bot blocker
This tutorial will be very similiar to the earlier OpenResty one I have already provided. However, this differs slightly due to the location of some of the files.
It works best with the instructions linked to above which create a seperate folder for all of the server block configurations to go in.
Download and test the bad bot blocker
Execute the following commands to download and test the bad bot blocker
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/local/sbin/install-ngxblockersudo chmod +x /usr/local/sbin/install-ngxblockercd /usr/local/sbinsudo ./install-ngxblocker
If everything goes well then execute the following commands to install the blocker and set the necessary permissions:
sudo ./install-ngxblocker -xsudo chmod +x /usr/local/sbin/setup-ngxblockersudo chmod +x /usr/local/sbin/update-ngxblocker
Run the setup script
Execute sudo ./setup-ngxblocker -w /var/www/html -e conf -v /etc/nginx/sites to test that everything will work as it should.
If you don't receive any error messages then execute sudo ./setup-ngxblocker -x -w /var/www/html -e conf -v /etc/nginx/sites to setup the bad bot blocker.
Now execute sudo nginx -t to test that there are no errors with the configuration changes so far. If there aren't any errors then execute sudo systemctl restart nginx.
Set up a cron job
In order to make sure that the bad bot blocker is updated (if needed) you need to set up a cronjob.
To do this enter sudo crontab -e and add the following line to the end of the file. Make sure to use your own email address.
00 22 * * * sudo /usr/local/sbin/update-ngxblocker -e [email protected]
