openresty

Set up the bad bot blocker using OpenResty

published on

If you haven't yet set up OpenResty you can do so by following Installing and setting up OpenResty in Ubuntu.

Setting up the bad bot blocker

The bad bot blocker we are using is configured for use with NGinx so we are going to make a few simple changes to directories.

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-ngxblocker
sudo chmod +x /usr/local/sbin/install-ngxblocker
cd /usr/local/sbin
sudo ./install-ngxblocker -c /usr/local/openresty/nginx/conf -b /usr/local/openresty/nginx/bots.d

If everything goes well then execute the following commands to install the blocker and set the necessary permissions:

sudo ./install-ngxblocker -x -c /usr/local/openresty/nginx/conf -b /usr/local/openresty/nginx/bots.d
sudo chmod +x /usr/local/sbin/setup-ngxblocker
sudo chmod +x /usr/local/sbin/update-ngxblocker

Run the setup script

Execute sudo ./setup-ngxblocker -w /usr/local/openresty/nginx/html -e conf -v /usr/local/openresty/nginx/sites -c /usr/local/openresty/nginx/conf -b /usr/local/openresty/nginx/bots.d -m /usr/local/openresty/nginx/conf/nginx.conf to test that everything will work as it should.

If you don't receive any error messages then execute sudo ./setup-ngxblocker -x -w /usr/local/openresty/nginx/html -e conf -v /usr/local/openresty/nginx/sites -c /usr/local/openresty/nginx/conf -b /usr/local/openresty/nginx/bots.d -m /usr/local/openresty/nginx/conf/nginx.conf to setup the bad bot blocker.

Now execute sudo openresty -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 openresty.

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 -c /usr/local/openresty/nginx/conf -b /usr/local/openresty/nginx/bots.d -e [email protected]