diff --git a/nginx/sites-available/git.itguys.com.br.conf b/nginx/sites-available/git.itguys.com.br.conf index 0048409..4191cb5 100644 --- a/nginx/sites-available/git.itguys.com.br.conf +++ b/nginx/sites-available/git.itguys.com.br.conf @@ -1,13 +1,13 @@ # ============================================================================== # ARQUIVO: /etc/nginx/sites-available/git.itguys.com.br.conf # AUTOR: Gemini (Especialista NGINX) -# DATA: 24/09/2025 - 20:32 -# VERSÃO: 3.0 (Adicionada compressão Brotli) +# DATA: 24/09/2025 - 20:39 +# VERSÃO: 4.0 (Adicionada Proteção Anti-Bot e Rate Limiting) # # DESCRIÇÃO: # Configuração de Proxy Reverso OTIMIZADA e SEGURA para Gitea. -# Esta versão adiciona a compressão Brotli como prioridade e mantém -# Gzip como fallback, garantindo a máxima compressão possível. +# Esta versão inclui bloqueio de bots/crawlers maliciosos por User-Agent +# e limitação de requisições por IP para mitigar abusos. # ============================================================================== # Define o nosso servidor Gitea como um "upstream" para fácil referência. @@ -44,6 +44,38 @@ server { access_log /var/log/nginx/git.itguys.com.br.access.log; error_log /var/log/nginx/git.itguys.com.br.error.log warn; + # ================================================================= + # INÍCIO: Definições de Proteção (Anti-Bot & Rate Limit) + # ================================================================= + + # --- Bloqueio de Crawlers e Bots Indesejados --- + # Se o User-Agent corresponder a algum da lista, a variável $bad_bot será 1. + if ($http_user_agent ~* (AhrefsBot|Baiduspider|BLEXBot|Bytespider|DotBot|SemrushBot|YandexBot|PetalBot|MJ12bot|MegaIndex|heritrix|Python-urllib|Wget|Go-http-client) ) { + set $bad_bot 1; + } + + # Bloqueia referrers de spam conhecidos. + if ( $http_referer ~* (semalt.com|buttons-for-website.com) ) { + set $bad_bot 1; + } + + # Bloqueia a requisição se for de um bot indesejado. + if ($bad_bot = 1) { + return 403; # Retorna 'Forbidden' + } + + # --- Limitação de Requisições por IP (Rate Limiting) --- + # A zona de memória 'ratelimit' deve ser definida em /etc/nginx/nginx.conf + # Ex: limit_req_zone $binary_remote_addr zone=ratelimit:10m rate=10r/s; + # Esta diretiva aplica a limitação definida na zona 'ratelimit'. + limit_req zone=ratelimit burst=20 nodelay; + + # ================================================================= + # FIM: Definições de Proteção + # ================================================================= + + # [ ... O restante do seu arquivo continua exatamente o mesmo ... ] + # ================================================================= # INÍCIO: Configurações de SSL/TLS # ================================================================= @@ -76,59 +108,14 @@ server { # ================================================================= # INÍCIO: Configurações de Compressão Brotli & Gzip # ================================================================= - # Prioriza o Brotli para navegadores modernos. brotli on; - brotli_comp_level 6; # Nível de compressão (1-11), 6 é um bom equilíbrio. - brotli_types - application/atom+xml - application/javascript - application/json - application/rss+xml - application/vnd.ms-fontobject - application/x-font-opentype - application/x-font-truetype - application/x-font-ttf - application/x-javascript - application/xhtml+xml - application/xml - font/eot - font/opentype - font/otf - font/truetype - image/svg+xml - image/x-icon - text/css - text/javascript - text/plain - text/xml; - - # Gzip serve como fallback para clientes/navegadores mais antigos. + brotli_comp_level 6; + brotli_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/x-icon text/css text/javascript text/plain text/xml; gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied expired no-cache no-store private auth; - gzip_types - application/atom+xml - application/javascript - application/json - application/rss+xml - application/vnd.ms-fontobject - application/x-font-opentype - application/x-font-truetype - application/x-font-ttf - application/x-javascript - application/xhtml+xml - application/xml - font/eot - font/opentype - font/otf - font/truetype - image/svg+xml - image/x-icon - text/css - text/javascript - text/plain - text/xml; + gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/x-icon text/css text/javascript text/plain text/xml; gzip_disable "MSIE [1-6]\."; # ================================================================= # FIM: Configurações de Compressão