[Auto-Sync] Atualização das configurações em srvproxy001.itguys.com.br - 2025-09-27 22:27:59
This commit is contained in:
parent
f10effd9f7
commit
83d1085f45
|
|
@ -1,33 +1,33 @@
|
|||
# ==============================================================================
|
||||
# ARQUIVO: /etc/nginx/sites-available/telefonia.itguys.com.br.conf
|
||||
# AUTOR: Gemini (Especialista NGINX)
|
||||
# DATA: 22/09/2025
|
||||
# DATA: 27/09/2025 (Consolidado e otimizado)
|
||||
#
|
||||
# DESCRIÇÃO:
|
||||
# Configuração de Proxy Reverso SEGURA e OTIMIZADA para MagnusBilling, criada
|
||||
# com base nas melhores práticas para aplicações PHP/Apache.
|
||||
# CONTEXTO:
|
||||
# Configuração de Proxy Reverso SEGURA e OTIMIZADA para MagnusBilling (PHP/Apache).
|
||||
# Todas as configurações de segurança (SSL/TLS e Headers) foram declaradas
|
||||
# diretamente neste arquivo, sem o uso de snippets.
|
||||
#
|
||||
# PRÉ-REQUISITOS:
|
||||
# - O IP deste servidor proxy DEVE estar na whitelist (ignoreip) do Fail2ban
|
||||
# no servidor de backend para evitar bloqueios 403 Forbidden.
|
||||
# UPSTREAM: 172.16.254.130 (Backend HTTP)
|
||||
# ==============================================================================
|
||||
|
||||
# Bloco Upstream: Define o servidor de backend da aplicação.
|
||||
# O uso de upstream facilita a manutenção e o balanceamento de carga futuro.
|
||||
upstream magnusbilling_backend {
|
||||
server 172.16.254.130;
|
||||
server 172.16.254.130; # Backend HTTP (NGINX faz o SSL Termination)
|
||||
keepalive 64;
|
||||
}
|
||||
|
||||
# ==============================================================================
|
||||
# ------------------------------------------------------------------------------
|
||||
# BLOCO 1: Redirecionamento de HTTP (porta 80) para HTTPS
|
||||
# O que faz? Garante que todo o tráfego seja criptografado.
|
||||
# ==============================================================================
|
||||
# ------------------------------------------------------------------------------
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name telefonia.itguys.com.br;
|
||||
|
||||
# Bloco para renovação do certificado SSL (Let's Encrypt).
|
||||
# Aplica o rate limiting básico (zona global_limit deve estar em nginx.conf)
|
||||
limit_req zone=global_limit burst=20 nodelay;
|
||||
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/html;
|
||||
}
|
||||
|
|
@ -38,51 +38,132 @@ server {
|
|||
}
|
||||
}
|
||||
|
||||
# ==============================================================================
|
||||
# ------------------------------------------------------------------------------
|
||||
# BLOCO 2: Servidor Principal HTTPS (porta 443)
|
||||
# O que faz? Processa todo o tráfego seguro e o envia para o MagnusBilling.
|
||||
# ==============================================================================
|
||||
# ------------------------------------------------------------------------------
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name telefonia.itguys.com.br;
|
||||
|
||||
# --- Configurações de Certificado SSL e Segurança ---
|
||||
# ============================================================================
|
||||
# LOGS, SEGURANÇA BÁSICA E RATE LIMITING
|
||||
# ============================================================================
|
||||
client_max_body_size 25M; # Tamanho razoável para uploads/arquivos de áudio
|
||||
access_log /var/log/nginx/telefonia.itguys.com.br.access.log combined;
|
||||
error_log /var/log/nginx/telefonia.itguys.com.br.error.log warn;
|
||||
# Log para acessos bloqueados por bots
|
||||
access_log /var/log/nginx/telefonia.itguys.com.br.bad-bot.log blocked if=$is_bad_bot;
|
||||
|
||||
# Módulo de Segurança Global (Bloqueia bots e URIs suspeitas de nginx.conf)
|
||||
if ($block_request) {
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Rate Limiting (zona global_limit deve estar em nginx.conf)
|
||||
limit_req zone=global_limit burst=50 nodelay;
|
||||
|
||||
# ============================================================================
|
||||
# CONFIGURAÇÕES DE SSL/TLS (Hardening)
|
||||
# ============================================================================
|
||||
ssl_certificate /etc/letsencrypt/live/telefonia.itguys.com.br/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/telefonia.itguys.com.br/privkey.pem;
|
||||
include /etc/nginx/snippets/ssl_params.conf; # Snippet com parâmetros de segurança SSL.
|
||||
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-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_timeout 1d;
|
||||
ssl_dhparam /etc/nginx/dhparam.pem;
|
||||
ssl_session_tickets off;
|
||||
|
||||
# --- Cabeçalhos de Segurança HTTP ---
|
||||
# Adicionam uma camada extra de proteção no navegador do cliente.
|
||||
# OCSP Stapling
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
ssl_trusted_certificate /etc/letsencrypt/live/telefonia.itguys.com.br/fullchain.pem;
|
||||
resolver 8.8.8.8 8.8.4.4 valid=300s;
|
||||
resolver_timeout 5s;
|
||||
|
||||
# ============================================================================
|
||||
# HEADERS DE SEGURANÇA
|
||||
# ============================================================================
|
||||
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 X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
add_header Referrer-Policy "no-referrer" always;
|
||||
add_header Permissions-Policy "geolocation=(), microphone=(), camera=(), payment=()" always;
|
||||
# CSP: O MagnusBilling é PHP, e esta é uma política de segurança baseada. Ajustar se plugins exigirem.
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; font-src 'self'; object-src 'none';" always;
|
||||
|
||||
# --- Logs de Acesso e Erro ---
|
||||
access_log /var/log/nginx/telefonia.itguys.com.br.access.log;
|
||||
error_log /var/log/nginx/telefonia.itguys.com.br.error.log warn;
|
||||
# ============================================================================
|
||||
# COMPRESSÃO
|
||||
# ============================================================================
|
||||
brotli on;
|
||||
brotli_comp_level 6;
|
||||
brotli_min_length 256;
|
||||
brotli_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_min_length 256;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
|
||||
|
||||
# --- Rota Principal para a Aplicação (/mbilling/) ---
|
||||
location /mbilling/ {
|
||||
# Parâmetros essenciais para o proxy reverso.
|
||||
include /etc/nginx/snippets/proxy_params.conf;
|
||||
|
||||
# Configurações para suportar WebSockets, usados pela interface do MagnusBilling.
|
||||
# ============================================================================
|
||||
# PARÂMETROS GLOBAIS DE PROXY
|
||||
# ============================================================================
|
||||
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_set_header X-Forwarded-Port $server_port;
|
||||
proxy_set_header User-Agent $http_user_agent;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_read_timeout 90s;
|
||||
proxy_send_timeout 90s;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
proxy_redirect off; # Evita problemas de redirecionamento no backend
|
||||
|
||||
# Envia a requisição para o servidor de backend definido no upstream.
|
||||
# ----------------------------------------------------------------------------
|
||||
# REGRAS DE ROTEAMENTO (LOCATIONS)
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 1. Rota para assets estáticos (CACHE AGRESSIVO)
|
||||
location ~* \.(?:css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff2?|ttf|eot)$ {
|
||||
proxy_cache magnusbilling_cache; # Criar esta zona no nginx.conf
|
||||
proxy_cache_valid 200 7d;
|
||||
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
|
||||
add_header Cache-Control "public, max-age=604800, immutable";
|
||||
add_header X-Proxy-Cache $upstream_cache_status;
|
||||
proxy_pass http://magnusbilling_backend;
|
||||
}
|
||||
|
||||
# --- Redirecionamento da Raiz ---
|
||||
# Para conveniência, redireciona quem acessa a raiz do domínio para a aplicação.
|
||||
# 2. Rota principal para a aplicação (/mbilling/) - Inclui WebSockets
|
||||
location /mbilling/ {
|
||||
# Configurações para suportar WebSockets
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# O Rate Limiting aqui é mais importante para proteger o /login e APIs
|
||||
# Se desejar limitar requisições específicas (ex.: /mbilling/login), crie uma zona dedicada.
|
||||
|
||||
proxy_pass http://magnusbilling_backend;
|
||||
}
|
||||
|
||||
# 3. Redirecionamento da Raiz
|
||||
location = / {
|
||||
return 302 /mbilling/;
|
||||
}
|
||||
|
||||
# --- Páginas de Erro Personalizadas (Opcional, mas recomendado) ---
|
||||
include /etc/nginx/snippets/custom_errors.conf;
|
||||
# 4. Bloqueio de arquivos e diretórios sensíveis (PHP, Git, etc.)
|
||||
location ~* /(?:composer\.(?:json|lock)|vendor/|etc/|var/|temp/|\.git/|\.env|setup\.php|install\.php) {
|
||||
deny all;
|
||||
return 404;
|
||||
}
|
||||
|
||||
# 5. Páginas de Erro Personalizadas
|
||||
# Incluir aqui as diretivas de error_page, se necessário.
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue