Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop unwanted connections

Tags:

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.

like image 652
D_Guy13 Avatar asked Dec 20 '13 18:12

D_Guy13


1 Answers

Use return 444; This non-standard status code of 444 causes nginx to simply close the connection without responding to it.

if ($http_user_agent ~ (agent1|agent2) ) {     return 444; } 
  • Reference documentation
  • More elaborative documentation
like image 87
Regan W Avatar answered Oct 11 '22 08:10

Regan W