169 lines
7.6 KiB
Plaintext
169 lines
7.6 KiB
Plaintext
# ==========================================================================================
|
|
# ARQUIVO: /etc/nginx/sites-available/zammad.itguys.com.br.conf
|
|
# DATA DA ALTERAÇÃO: 2025-09-27 22:56
|
|
#
|
|
# AUDITORIA E OTIMIZAÇÃO POR GEMINI
|
|
# VERSÃO: 2.1 (Carateres Invisíveis Removidos - Alinhada com Estrutura Global)
|
|
#
|
|
# MELHORIAS APLICADAS NESTA VERSÃO:
|
|
# 1. REMOÇÃO DE CARACTERES ESPECIAIS: Garantindo compatibilidade pura NGINX.
|
|
# 2. REMOÇÃO DE SNIPPETS: Todas as diretivas incluídas foram internalizadas.
|
|
# 3. INTEGRAÇÃO COM MÓDULO DE SEGURANÇA GLOBAL: Uso de $block_request para bots/URI suspeitas.
|
|
# 4. SSL/TLS OTIMIZADO: Implementação das melhores práticas (TLS 1.2/1.3, Ciphers fortes, OCSP).
|
|
# 5. HEADERS DE SEGURANÇA REFORÇADOS: HSTS Preload e Permissions-Policy adicionados.
|
|
# 6. COMPRESSÃO: Brotli e Gzip ativados.
|
|
# 7. LOGS DEDICADOS: Logs separados para acesso, erros e bad bots.
|
|
# ==========================================================================================
|
|
|
|
# Mapa para definir o tempo de expiração do cache de assets
|
|
# O Zammad utiliza /assets/ com nomes de arquivos versionados, permitindo cache agressivo.
|
|
|
|
# UPSTREAMS
|
|
upstream zammad_backend {
|
|
# Backend principal da aplicação Zammad.
|
|
server 172.16.254.59;
|
|
}
|
|
upstream zammad_websocket_backend {
|
|
# Backend específico para o serviço de WebSocket do Zammad (porta 6042).
|
|
server 172.16.254.59:6042;
|
|
}
|
|
|
|
# ======================================================================
|
|
# BLOCO HTTP: Redirecionar para HTTPS
|
|
# ======================================================================
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name zammad.itguys.com.br;
|
|
|
|
# Aplica o rate limiting a todo o tráfego HTTP.
|
|
limit_req zone=global_limit burst=20 nodelay;
|
|
|
|
# Responde ao desafio do Let's Encrypt
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/html;
|
|
}
|
|
|
|
# Redireciona todo o resto para HTTPS
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# ======================================================================
|
|
# BLOCO HTTPS: Servidor Principal Otimizado
|
|
# ======================================================================
|
|
server {
|
|
listen 443 ssl http2;
|
|
listen [::]:443 ssl http2;
|
|
server_name zammad.itguys.com.br;
|
|
|
|
# --- Configurações Gerais e Logs ---
|
|
client_max_body_size 50M;
|
|
access_log /var/log/nginx/zammad.itguys.com.br.access.log detailed_proxy;
|
|
error_log /var/log/nginx/zammad.itguys.com.br.error.log warn;
|
|
# Log dedicado para bots suspeitos/acessos bloqueados
|
|
access_log /var/log/nginx/zammad.itguys.com.br.bad-bot.log suspicious_bot if=$is_bad_bot;
|
|
|
|
# --- Módulo de Segurança Global (assumindo $block_request em nginx.conf) ---
|
|
# Bloqueia bots e acesso a URIs suspeitas de forma centralizada.
|
|
if ($block_request) {
|
|
return 404; # Retornar 404 é mais discreto que 403 para scanners
|
|
}
|
|
|
|
# --- Aplica o Rate Limiting (zona definida em nginx.conf) ---
|
|
limit_req zone=global_limit burst=100 nodelay;
|
|
|
|
# --- Parâmetros de SSL/TLS (Best Practices) ---
|
|
ssl_certificate /etc/letsencrypt/live/zammad.itguys.com.br/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/zammad.itguys.com.br/privkey.pem;
|
|
ssl_protocols TLSv1.3 TLSv1.2;
|
|
# Ciphers conforme guia SSL Labs (forte, compatível com Apple/Android)
|
|
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-AES256-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_cache é assumido como definido globalmente em nginx.conf
|
|
ssl_session_timeout 1d;
|
|
ssl_dhparam /etc/nginx/dhparam.pem; # Assumindo um arquivo dhparam seguro e recente
|
|
ssl_session_tickets off;
|
|
|
|
# OCSP Stapling (Melhora a performance e a segurança)
|
|
ssl_stapling on;
|
|
ssl_stapling_verify on;
|
|
ssl_trusted_certificate /etc/letsencrypt/live/zammad.itguys.com.br/fullchain.pem;
|
|
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;
|
|
# Content-Security-Policy (CSP) geralmente é mais seguro gerenciar na aplicação.
|
|
|
|
# --- Bloco de Compressão ---
|
|
brotli on;
|
|
brotli_comp_level 6;
|
|
brotli_min_length 256;
|
|
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_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_min_length 256;
|
|
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;
|
|
|
|
# --- Parâmetros de Proxy Reversos (Base) ---
|
|
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;
|
|
proxy_set_header X-Forwarded-Host $host;
|
|
proxy_buffering on; # Certifica que o buffering está ligado
|
|
proxy_buffer_size 128k;
|
|
proxy_buffers 4 256k; # 4 buffers de 256KB cada.
|
|
proxy_busy_buffers_size 256k;
|
|
proxy_max_temp_file_size 0; # Desabilita a escrita em disco, forçando buffer na memória (se tiver RAM suficiente)
|
|
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
|
|
|
|
# --- REGRAS DE ROTEAMENTO (LOCATIONS) ---
|
|
|
|
# 1. Rota para WebSockets (SEM CACHE)
|
|
location /ws {
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_read_timeout 86400s;
|
|
|
|
# GARANTIR O PROTOCOLO E A PORTA CORRETA PARA O ZAMMAD
|
|
proxy_set_header X-Forwarded-Proto https; # Define explicitamente como HTTPS
|
|
proxy_set_header X-Forwarded-Port 443;
|
|
proxy_set_header X-Forwarded-Ssl on;
|
|
|
|
proxy_pass http://zammad_websocket_backend;
|
|
}
|
|
|
|
# 2. Rota para assets estáticos (/assets/) - CACHE AGRESSIVO
|
|
location /assets/ {
|
|
# O $cache_asset está definido no 'map' no topo do arquivo.
|
|
expires $cache_asset; # 1 ano de cache para assets com hash
|
|
|
|
# Parâmetros de cache do NGINX
|
|
proxy_cache zammad_cache;
|
|
proxy_cache_valid 200 7d;
|
|
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
|
|
add_header Cache-Control "public, max-age=604800, immutable";
|
|
|
|
proxy_pass http://zammad_backend;
|
|
}
|
|
|
|
# 3. Rota principal para a aplicação (SEM CACHE)
|
|
location / {
|
|
proxy_pass http://zammad_backend;
|
|
}
|
|
}
|