Até onde eu sei, o módulo Auth Basic não suporta esse recurso, mas você pode fazer isso usando Fail2ban .
Testando com um usuário inexistente, você verá algo como belows no log de erros:
2012/08/25 10:07:01 [error] 5866#0: *1 no user/password was provided for basic authentication, client: 127.0.0.1, server: localhost, request: "GET /pma HTTP/1.1", host: "localhost:81"
2012/08/25 10:07:04 [error] 5866#0: *1 user "ajfkla" was not found in "/etc/nginx/htpasswd", client: 127.0.0.1, server: localhost, request: "GET /pma HTTP/1.1", host: "localhost:81"
Em seguida, crie o filtro necessário:
/etc/fail2ban/filter.d/nginx-auth.conf
[Definition]
failregex = no user/password was provided for basic authentication.*client: <HOST>
user .* was not found in.*client: <HOST>
user .* password mismatch.*client: <HOST>
ignoreregex = </host></host></host>
/etc/fail2ban/jail.conf
[nginx-auth]
enabled = true
filter = nginx-auth
action = iptables[name=NoAuthFailures, port=80, protocol=tcp]
logpath = /var/log/nginx*/*error*.log
bantime = 3600 # 1 hour
maxretry = 3
Testando regras do Fail2Ban:
fail2ban-regex /var/log/nginx/localhost.error_log /etc/fail2ban/filter.d/nginx-auth.conf
Failregex
|- Regular expressions:
| [1] no user/password was provided for basic authentication.*client: <HOST>
| [2] user .* was not found in.*client: <HOST>
| [3] user .* password mismatch.*client: <HOST>
|
'- Number of matches:
[1] 1 match(es)
[2] 2 match(es)
[3] 0 match(es)
Ignoreregex
|- Regular expressions:
|
'- Number of matches:
Summary
=======
Addresses found:
[1]
127.0.0.1 (Sat Aug 25 10:07:01 2012)
[2]
127.0.0.1 (Sat Aug 25 10:07:04 2012)
127.0.0.1 (Sat Aug 25 10:07:07 2012)
[3]
PS: Como o Fail2ban busca arquivos de log para banir, verifique se logpath
corresponde à sua configuração.