diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 7e363ba..f12d790 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -63,6 +63,7 @@ http { proxy_cache_path /var/cache/nginx/unifi_cache levels=1:2 keys_zone=unifi_cache:10m inactive=60m max_size=1g; proxy_cache_path /var/cache/nginx/magnusbilling_cache levels=1:2 keys_zone=magnusbilling_cache:10m max_size=1g inactive=7d use_temp_path=off; proxy_cache_path /var/cache/nginx/workspace_cache levels=1:2 keys_zone=workspace_cache:10m max_size=1g inactive=60m use_temp_path=off; + proxy_cache_path /var/cache/nginx/solucionei_cache levels=1:2 keys_zone=solucionei_cache:20m max_size=2g inactive=90d use_temp_path=off; # --- DEFINIÇÃO DE CAPACIDADES DE SEGURANÇA (OBRIGATÓRIO AQUI) --- # Define as 'variáveis' e 'zonas' que os sites podem usar para segurança. diff --git a/nginx/sites-available/solucionei.itguys.com.br.conf b/nginx/sites-available/solucionei.itguys.com.br.conf new file mode 100644 index 0000000..152882c --- /dev/null +++ b/nginx/sites-available/solucionei.itguys.com.br.conf @@ -0,0 +1,139 @@ +# ========================================================================================== +# ARQUIVO: /etc/nginx/sites-available/solucionei.itguys.com.br.conf +# AUTOR: Gemini (Especialista NGINX) +# DATA: 2025-10-14 +# VERSÃO: 1.0 +# +# DESCRIÇÃO: +# Configuração de proxy reverso para Solucionei, otimizada para múltiplos usuários. +# - Cache agressivo para assets estáticos para alta performance. +# - Integração completa com as políticas globais de segurança (bot block, rate limit). +# - Otimizações de SSL/TLS, incluindo OCSP Stapling. +# - Headers de segurança reforçados (HSTS, Permissions-Policy). +# - Compressão Brotli e Gzip. +# - Logs dedicados para monitoramento completo. +# ========================================================================================== + +# UPSTREAM: Define o servidor backend da aplicação. +upstream solucionei_backend { + server 172.16.121.16; +} + +# ====================================================================== +# BLOCO 1: Servidor HTTP (Porta 80) +# - Responde ao desafio Let's Encrypt. +# - Redireciona todo o tráfego para HTTPS. +# ====================================================================== +server { + listen 80; + listen [::]:80; + server_name solucionei.itguys.com.br; + + # Local para validação do Certbot. + location /.well-known/acme-challenge/ { + root /var/www/html; + } + + # Redirecionamento permanente para HTTPS. + location / { + return 301 https://$host$request_uri; + } +} + +# ====================================================================== +# BLOCO 2: Servidor HTTPS (Porta 443) +# - Bloco principal com todas as otimizações e configurações de segurança. +# ====================================================================== +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name solucionei.itguys.com.br; + + # --- Configurações Gerais e Logs Dedicados --- + client_max_body_size 50M; + access_log /var/log/nginx/solucionei.itguys.com.br.access.log detailed_proxy; + error_log /var/log/nginx/solucionei.itguys.com.br.error.log warn; + access_log /var/log/nginx/solucionei.itguys.com.br.bad-bot.log suspicious_bot if=$block_request; + + # --- Módulo de Segurança Global (integrado com nginx.conf) --- + if ($block_request) { + return 404; + } + limit_req zone=global_limit burst=100 nodelay; + + # --- Parâmetros de SSL/TLS (Best Practices) --- + # O Certbot irá gerenciar os caminhos abaixo. + ssl_certificate /etc/letsencrypt/live/solucionei.itguys.com.br/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/solucionei.itguys.com.br/privkey.pem; + ssl_trusted_certificate /etc/letsencrypt/live/solucionei.itguys.com.br/fullchain.pem; + + ssl_protocols TLSv1.3 TLSv1.2; + ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES265-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305'; + ssl_prefer_server_ciphers on; + ssl_ecdh_curve X25519:secp256r1:secp384r1; + ssl_session_timeout 1d; + ssl_session_tickets off; + ssl_dhparam /etc/nginx/dhparam.pem; + + # OCSP Stapling + ssl_stapling on; + ssl_stapling_verify on; + resolver 8.8.8.8 8.8.4.4 valid=300s; + resolver_timeout 5s; + + # --- Cabeçalhos de Segurança Otimizados --- + add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-Frame-Options "SAMEORIGIN" always; + add_header Referrer-Policy "no-referrer" always; + add_header Permissions-Policy "geolocation=(), midi=(), sync-xhr=(self), microphone=(), camera=(), magnetometer=(), gyroscope=(), fullscreen=(self), payment=()" always; + + # --- Compressão (Brotli e Gzip) --- + brotli on; + brotli_comp_level 6; + brotli_types application/atom+xml application/javascript application/json text/css text/javascript text/plain text/xml image/svg+xml; + + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_types application/atom+xml application/javascript application/json text/css text/javascript text/plain text/xml image/svg+xml; + + # --- REGRAS DE ROTEAMENTO E CACHE --- + + # 1. Rota para assets estáticos (CACHE OTIMIZADO) + # Cacheia agressivamente arquivos que não mudam com frequência. + location ~* \.(?:css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff2?|ttf|eot)$ { + proxy_pass http://solucionei_backend; + proxy_set_header Host $host; + + # Parâmetros de cache do NGINX + proxy_cache solucionei_cache; # ATENÇÃO: Zona de cache dedicada + proxy_cache_valid 200 30d; # Cache de 30 dias para respostas 200 OK + proxy_cache_revalidate on; # Permite que o cliente valide o cache (If-Modified-Since) + proxy_cache_lock on; # Evita que múltiplas requisições recriem o mesmo item de cache + proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; + add_header X-Proxy-Cache $upstream_cache_status; + + # Headers de cache para o navegador (30 dias) + expires 30d; + add_header Cache-Control "public, immutable"; + } + + # 2. Rota principal para a aplicação (SEM CACHE) + location / { + proxy_pass http://solucionei_backend; + + # Cabeçalhos essenciais para a aplicação backend. + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # Suporte para WebSockets. + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_read_timeout 86400s; + } +}