118 lines
4.9 KiB
Plaintext
118 lines
4.9 KiB
Plaintext
# ==============================================================================
|
|
# ARQUIVO: /etc/nginx/sites-available/anatram.com.br.conf
|
|
# AUTOR: Gemini (Especialista NGINX)
|
|
# DATA: 27/09/2025 - 17:09
|
|
# VERSÃO: 2.0 (Padronização, Hardening de Segurança e Rate Limiting)
|
|
#
|
|
# DESCRIÇÃO:
|
|
# Configuração de Proxy Reverso para o site anatram.com.br.
|
|
# Esta versão implementa as políticas globais de segurança e logging, corrige
|
|
# uma vulnerabilidade na verificação do SSL do backend e adiciona rate limiting.
|
|
# ==============================================================================
|
|
|
|
# ==============================================================================
|
|
# BLOCO 1: Redirecionamento de HTTP (porta 80) para HTTPS
|
|
# ==============================================================================
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name anatram.com.br;
|
|
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/html;
|
|
}
|
|
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# ==============================================================================
|
|
# BLOCO 2: Servidor Principal - Proxy Reverso (HTTPS)
|
|
# ==============================================================================
|
|
server {
|
|
listen 443 ssl http2;
|
|
listen [::]:443 ssl http2;
|
|
server_name anatram.com.br;
|
|
|
|
# --- Logs ---
|
|
access_log /var/log/nginx/anatram.com.br.access.log detailed_proxy;
|
|
access_log /var/log/nginx/anatram.com.br.bad-bot.log suspicious_bot if=$block_request;
|
|
error_log /var/log/nginx/anatram.com.br.error.log warn;
|
|
|
|
# --- Segurança (Integração com nginx.conf) ---
|
|
if ($block_request) {
|
|
return 444; # Fecha a conexão sem resposta, eficaz contra bots.
|
|
}
|
|
|
|
# Aplica rate limiting global e um limite mais estrito para bots.
|
|
limit_req zone=global_limit burst=20 nodelay;
|
|
limit_req zone=bad_bot_limit;
|
|
|
|
# --- Configurações de SSL/TLS (Padronizadas) ---
|
|
ssl_certificate /etc/letsencrypt/live/anatram.com.br/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/anatram.com.br/privkey.pem;
|
|
ssl_trusted_certificate /etc/letsencrypt/live/anatram.com.br/fullchain.pem; # Padronizado
|
|
ssl_dhparam /etc/nginx/dhparam.pem;
|
|
ssl_session_timeout 1d;
|
|
ssl_session_tickets off;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_prefer_server_ciphers off; # Padronizado
|
|
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 ---
|
|
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;
|
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
|
|
# ATENÇÃO: Esta CSP é muito restritiva. Se o site usar recursos externos (CDNs, Google Fonts, etc.), eles precisarão ser adicionados aqui.
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; connect-src 'self'; object-src 'none'; frame-ancestors 'self';" always;
|
|
|
|
# --- Configurações de 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_comp_level 6;
|
|
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss image/svg+xml;
|
|
gzip_disable "MSIE [1-6]\.";
|
|
|
|
# --- Parâmetros de Proxy (Com Hardening) ---
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
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_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# --- Estratégia de Cache ---
|
|
proxy_cache static_cache;
|
|
add_header X-Proxy-Cache $upstream_cache_status;
|
|
|
|
# --- REGRAS DE ROTEAMENTO (LOCATIONS) ---
|
|
location ~* \.(?:css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff2?|ttf|eot)$ {
|
|
proxy_pass https://172.16.12.9:443;
|
|
proxy_cache_valid 200 30d;
|
|
proxy_cache_valid any 1m;
|
|
expires 30d;
|
|
add_header Cache-Control "public";
|
|
access_log off;
|
|
}
|
|
|
|
location / {
|
|
proxy_pass https://172.16.12.9:443;
|
|
proxy_no_cache 1;
|
|
proxy_cache_bypass 1;
|
|
}
|
|
}
|