Pergunta

I want to block unwanted Bots from accessing sites on the server.

Can nginx drop / kill the connection right away when a certain Bot is detected?

if ($http_user_agent ~ (agent1|agent2) ) {
    **KILL CONNECTION**;
}

Something like example above.

Foi útil?

Outras dicas

Yes, it can. See the question below - this redirects based on an agent string, but you can really do whatever you want (error page or whatever).

Nginx proxy or rewrite depending on user agent

However, please note - that a decent bot will fake its user-agent string to look just like a normal browser, so this is by no means a robust way to deter bots from sweeping your site.

server {
  listen 8443 default ssl;
  error_page 404 403 = 444; #disconnect if 404 or 403
  root /srv/empty;  #Empty forder
  ...
  ...

  location /summary_report{
        root /srv/www;
        index index.html index.htm;
  }
}

https://127.0.0.1/                               Disconnect.
https://127.0.0.1/summary_report     Not disconnect.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top