diff --git a/nginx/sites-available/ferreirareal.com.br.conf b/nginx/sites-available/ferreirareal.com.br.conf new file mode 100644 index 0000000..81b59cf --- /dev/null +++ b/nginx/sites-available/ferreirareal.com.br.conf @@ -0,0 +1,135 @@ +# ============================================================================== +# ARQUIVO: /etc/nginx/sites-available/ferreirareal.com.br.conf +# AUTOR: Gemini (Especialista NGINX) +# DATA: 27/09/2025 - 17:56 +# VERSÃO: 2.0 (Padrão Autocontido com Foco em Performance e Segurança) +# +# DESCRIÇÃO: +# Refatoração completa para site estático. Elimina snippets e adiciona +# compressão (Brotli/Gzip) e cache de navegador para máxima performance. +# Integra todas as políticas globais de segurança e logging. +# ============================================================================== + +# ============================================================================== +# BLOCO 1: Redirecionamento de HTTP (porta 80) para HTTPS COM WWW +# ============================================================================== +server { + listen 80; + listen [::]:80; + server_name ferreirareal.com.br www.ferreirareal.com.br; + + location /.well-known/acme-challenge/ { + root /var/www/html; + } + + location / { + return 301 https://www.ferreirareal.com.br$request_uri; + } +} + +# ============================================================================== +# BLOCO 2: Redirecionamento de HTTPS SEM WWW para a versão COM WWW +# ============================================================================== +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name ferreirareal.com.br; + + # --- Configurações de SSL (Autocontido) --- + ssl_certificate /etc/letsencrypt/live/www.ferreirareal.com.br/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/www.ferreirareal.com.br/privkey.pem; + ssl_trusted_certificate /etc/letsencrypt/live/www.ferreirareal.com.br/fullchain.pem; + ssl_session_timeout 1d; + ssl_session_cache shared:SSL:60m; + ssl_session_tickets off; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_prefer_server_ciphers off; + ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; + ssl_stapling on; + ssl_stapling_verify on; + + return 301 https://www.ferreirareal.com.br$request_uri; +} + +# ============================================================================== +# BLOCO 3: Servidor Principal - PROXY REVERSO COM CACHE (HTTPS COM WWW) +# ============================================================================== +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name www.ferreirareal.com.br; + + # --- Logs Dedicados (Padronizado) --- + access_log /var/log/nginx/ferreirareal.com.br.access.log detailed_proxy; + access_log /var/log/nginx/ferreirareal.com.br.bad-bot.log suspicious_bot if=$block_request; + error_log /var/log/nginx/ferreirareal.com.br.error.log warn; + + # --- Segurança (Integração com nginx.conf) --- + if ($block_request) { + return 404; + } + limit_req zone=global_limit burst=100 nodelay; # Burst alto para site com muitos assets + limit_req zone=bad_bot_limit; + + # --- Configurações de SSL/TLS (Padrão Autocontido) --- + ssl_certificate /etc/letsencrypt/live/www.ferreirareal.com.br/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/www.ferreirareal.com.br/privkey.pem; + ssl_trusted_certificate /etc/letsencrypt/live/www.ferreirareal.com.br/fullchain.pem; + ssl_session_timeout 1d; + ssl_session_cache shared:SSL:60m; + ssl_session_tickets off; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_prefer_server_ciphers off; + ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; + ssl_stapling on; + ssl_stapling_verify on; + + # --- Cabeçalhos de Segurança (Padrão Autocontido) --- + add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "no-referrer-when-downgrade" always; + # CSP para um site estático simples. + add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self'; font-src 'self'; object-src 'none'; frame-ancestors 'none';" always; + + # --- OTIMIZAÇÃO DE PERFORMANCE: Compressão Brotli & Gzip --- + brotli on; + brotli_comp_level 6; + brotli_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss image/svg+xml; + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_proxied any; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss image/svg+xml; + + # --- Configuração de Cache de Proxy --- + proxy_cache static_cache; + add_header X-Proxy-Cache $upstream_cache_status; + proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; + proxy_cache_revalidate on; + proxy_cache_lock on; + + # --- Parâmetros de Proxy (Autocontido) --- + 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; + + # --- REGRAS DE ROTEAMENTO (LOCATIONS) --- + + # 1. Rota para Arquivos Estáticos (Cache Agressivo de NGINX e Navegador) + location ~* \.(?:css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff2?|ttf|eot)$ { + proxy_pass http://172.16.12.5:80; + proxy_cache_valid 200 30d; + access_log off; + # OTIMIZAÇÃO DE PERFORMANCE: Cache de Navegador + expires 1y; + add_header Cache-Control "public, immutable"; + } + + # 2. Rota Principal para HTML (Cache Curto no NGINX, sem cache no navegador) + location / { + proxy_pass http://172.16.12.5:80; + proxy_cache_valid 200 10m; + } +}