A
A
Alexander2020-05-23 14:22:27
Nginx
Alexander, 2020-05-23 14:22:27

How to block bots on nginx less resourcefully - by IP or user-agent?

There is a VPS with ISPmanager panel and nginx+php-fpm. Bot PetalBot storms one of the sites (but I would even block it for everyone just in case). It is better to prescribe access prohibition by user-agent in the nginx config for the site

if ($http_user_agent ~* PetalBot) {
      return 403;
  }

or deny access for the IP range
location / {
    deny  114.119.160.0/16;
    deny  114.119.161.0/16;
    deny  114.119.162.0/16;
    deny  114.119.163.0/16;
    deny  114.119.164.0/16;
    deny  114.119.165.0/16;
    deny  114.119.166.0/16;
    deny  114.119.167.0/16;
}


Or somehow it is necessary to prohibit even earlier and then even in the access.log logs they will not be fixed? I don't know much about setting up servers.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
ky0, 2020-05-23
@ky0

Kill on the firewall by address ranges - then nothing will appear in the logs.

K
Karpion, 2020-05-24
@Karpion

If the attacks are targeted, then a hacker can change the user_agent without any problems. I advise you to ban both by IP address and by user_agent.

A
AnrDaemon, 2020-06-03
@AnrDaemon

That's only if you are blocking exactly unwanted bots, it's better to `return 444;`

I
Ivan Ivanov, 2021-03-27
@romalu

Yes, I also created an overload. This is a huawei search engine robot - https://vk.com/@news_newusman-rss-722804822-1394310157 - just block it in robots. You can still end up in htaccess or nginx, to be sure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question