It seems I spend most of my time moderating comments on my websites just to delete spam. It is still a daily task which sometimes is amazing how much the Wordpress Askimet plugin catches. It works amazingly well but it still requires time to sort through all the junk mail to ensure nothing was caught by accident.
I stumbled across a feature in NGINX that helps you block website visitors based on the keywords they have in their HTTP header. For example, if a spammer posts a comment about Viagra. NGINX catches the keyword Viagra in the HTTP header and redirects the user to another page.
Steps for blocking Spam with NGINX
- Navigate to your NGINX sites-enabled config file. Usually located in: /etc/nginx/sites-enabled/<config file name>
- Edit the config file with your preferred editor
- Copy the below code to your config file:
- Modify the keywords to block specific keywords which are giving you trouble. Be sure to separate the keywords with a pipe ¦
- Save your changes
- Run the command nginx -t to test the config file for errors. Only if it passes successfully should you continue to the next step. If not go back to the config and fix the problems first
- Reload NGINX by running : service nginx reload
Subscribe to BrianChristner.io
Get the latest posts delivered right to your inbox