Use Fail2ban for banning Bots ? Or Use Nginx for refusing Bots ?

Posted July 1, 2016 4.9k views
NginxUbuntuServer OptimizationSecurityFirewallMonitoringLEMP

Hi all,

First of all, does anyone know if F2B is only for other purposes than protecting authentication processes ? As far as I can know from reading, it can also ban some bots (see : BadBots filter). In that case, it would also be able to ban normal ‘bad’ traffic (from the bots) …

Question 1 : Is this the case ? So, F2B is not only used in context of authentication ?

Also, I read here : , that NGINX can be used to refuse bots.

Question 2 : which method would be preferable, in a sense of maintaining server speed and / or which method is better overall ?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

The primary difference here is that fail2ban in general will manage a list, using activity to add new sources to a method of blocking them (usually a firewall). The nginx method you listed utilizes a static list of things to block. If you have such a list, the nginx method may be easier on your resources but the bot traffic would still reach the nginx process. Using fail2ban may allow more flexibility and would prevent those requests from ever reaching nginx once they are recognized.

  • Thanks for your reply … however I am thinking … : when I look into the filters that F2B uses for badbots, I can see that it checks the access log … aren’t the access logs written by nginx after the requests are made ? … doesn’t that mean that bot has already reached the nginx process ?

    • I have not personally used f2b with a web service much but in general f2b watches for activity that matches what it’s looking for. In most cases this is a pattern of behavior. For SSH it will block a certain IP after so many failed authentication attempts. Since f2b builds it’s block list as it goes it uses the logs to see if a request matches a pattern of behavior. Once there is enough data to match that pattern then it takes action to block further attempts. This will let the first few requests from a new IP through. The nginx option you listed uses a static list, so while that solution would not let the first request through, it would only block those clients who are already listed in the file.