[Auto-Sync] Atualização das configurações em srvproxy001.itguys.com.br - 2025-09-27 13:48:59

This commit is contained in:
srvproxy001.itguys.com.br 2025-09-27 13:48:59 -03:00
parent dfd01f1e80
commit 84a5be0ff9
1 changed files with 51 additions and 83 deletions

View File

@ -1,89 +1,37 @@
# ==========================================================================================
# ARQUIVO: /etc/nginx/sites-available/cloud.grupopralog.com.br.conf
# DATA DA ALTERAÇÃO: 2025-09-26 23:48
# DATA DA ALTERAÇÃO: 2025-09-27 13:45
#
# AUDITORIA E OTIMIZAÇÃO POR GEMINI
# VERSÃO: 10.0 (Configuração Unificada com Rate Limit Inteligente)
# VERSÃO: 11.0 (Refatorado para Estrutura Global)
#
# MELHORIAS APLICADAS NESTA VERSÃO:
# 1. RATE LIMIT INTELIGENTE COM WHITELIST:
# - Limita requisições apenas para IPs externos (internet).
# - IGNORA o limite para IPs da rede interna/confiáveis, evitando bloqueios
# para colaboradores.
# 1. REMOÇÃO DE DIRETIVAS GLOBAIS:
# - As diretivas 'geo', 'map', 'limit_req_zone' e 'proxy_cache_path' foram removidas
# deste arquivo, pois agora são gerenciadas centralmente em /etc/nginx/nginx.conf.
#
# 2. CONFIGURAÇÃO SELF-CONTAINED:
# - Toda a lógica (geo, map, limit_req_zone) foi adicionada a este arquivo
# para simplificar a manutenção, não sendo necessário editar o nginx.conf.
# 2. INTEGRAÇÃO COM MÓDULO DE SEGURANÇA GLOBAL:
# - Substituídos os antigos blocos 'if' e 'location' por uma única verificação
# da variável '$block_request', definida no nginx.conf.
#
# 3. CABEÇALHOS DE SEGURANÇA CORRIGIDOS E ATUALIZADOS.
# 3. CONFIGURAÇÃO ALINHADA E SIMPLIFICADA.
# ==========================================================================================
# ======================================================================
# INÍCIO - LÓGICA DE WHITELIST PARA RATE LIMIT
# LÓGICA DE WHITELIST E RATE LIMIT MOVIDA PARA /etc/nginx/nginx.conf
# ======================================================================
# 1. Bloco GEO: Define uma variável $is_internal como '1' se o IP do cliente
# estiver na nossa lista de redes confiáveis. Caso contrário, será '0'.
geo $is_internal {
default 0;
# --- IPs PÚBLICOS de Unidades/Escritórios (CENÁRIO A - RECOMENDADO) ---
# ESSA É A PARTE MAIS IMPORTANTE. PREENCHA COM OS IPs PÚBLICOS REAIS
# DE ONDE SEUS COLABORADORES ACESSAM A INTERNET.
# ----------------- PREENCHA AQUI OS SEUS IPS PÚBLICOS -----------------
# Ex: 200.201.202.203 1; # Matriz - São Paulo
# Ex: 189.188.187.186 1; # Filial - Rio de Janeiro
45.169.73.155 1;
201.73.213.130 1;
177.74.160.17 1;
177.74.160.18 1;
177.74.160.19 1;
177.74.160.20 1;
177.74.160.21 1;
177.74.160.22 1;
177.74.160.23 1;
45.169.87.168 1;
45.169.87.169 1;
45.169.87.170 1;
45.169.87.171 1;
45.169.87.172 1;
45.169.87.173 1;
45.169.87.174 1;
45.169.87.175 1;
# --- Redes PRIVADAS (CENÁRIO B - AVANÇADO) ---
# Esta seção só funcionará se você tiver um outro proxy na frente do NGINX
# que envie o IP original do cliente no header X-Forwarded-For.
10.10.0.0/16 1;
10.11.0.0/16 1;
10.12.0.0/16 1;
172.16.0.0/16 1;
}
# 2. Bloco MAP: Cria a chave para o rate limit.
# - Se o IP for interno ($is_internal = 1), a chave será vazia (sem limite).
# - Se o IP for externo ($is_internal = 0), a chave será o IP do cliente (com limite).
map $is_internal $limit_key {
0 $binary_remote_addr;
1 "";
}
# 3. Definição da ZONA de Rate Limit. Usa a chave dinâmica $limit_key.
# Apenas chaves não vazias (IPs externos) serão limitadas.
limit_req_zone $limit_key zone=global_limit:20m rate=10r/s;
# ======================================================================
# FIM - LÓGICA DE WHITELIST
# DEFINIÇÃO DE CACHE MOVIDA PARA /etc/nginx/nginx.conf
# ======================================================================
# B. CONFIGURAÇÃO DA ZONA DE CACHE (Server-Side)
proxy_cache_path /var/cache/nginx/nextcloud_cache_grupopralog levels=1:2 keys_zone=nextcloud_cache:20m max_size=2g inactive=120m use_temp_path=off;
# Mapa para definir o tempo de expiração do cache de assets
map $request_uri $cache_asset {
~*\.(css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff|woff2|ttf|otf)$ 1y;
default off;
}
# C. UPSTREAMS
# UPSTREAMS
upstream nextcloud_backend {
server 172.16.253.12;
}
@ -91,7 +39,7 @@ upstream officeonline_backend {
server 172.16.253.101;
}
# D. BLOCO HTTP: Redirecionar para HTTPS
# BLOCO HTTP: Redirecionar para HTTPS
server {
listen 80;
listen [::]:80;
@ -100,25 +48,35 @@ server {
# 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;
}
}
# E. BLOCO HTTPS: Servidor Principal Otimizado
# BLOCO HTTPS: Servidor Principal Otimizado
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name cloud.grupopralog.com.br;
# --- Configurações Gerais ---
client_max_body_size 10G;
access_log /var/log/nginx/cloud.grupopralog.com.br.access.log detailed_proxy;
error_log /var/log/nginx/cloud.grupopralog.com.br.error.log warn;
# --- Aplica o Rate Limiting para o servidor principal ---
# --- Módulo de Segurança Global (definido em nginx.conf) ---
# Bloqueia bots e acesso a URIs suspeitas de forma centralizada.
if ($block_request) {
return 404; # Retornar 404 é mais discreto que 403
}
# --- Aplica o Rate Limiting (zona definida em nginx.conf) ---
limit_req zone=global_limit burst=100 nodelay;
# --- Parâmetros de SSL/TLS (Ciphers atualizados conforme best practices) ---
@ -128,7 +86,7 @@ server {
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 shared:SSL:50m;
# ssl_session_cache é definido globalmente em nginx.conf
ssl_session_timeout 1d;
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_session_tickets off;
@ -143,11 +101,11 @@ server {
# --- Cabeçalhos de Segurança Otimizados ---
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
proxy_hide_header "X-Frame-Options";
proxy_hide_header "Feature-Policy";
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "no-referrer" always;
add_header Permissions-Policy "geolocation=(), midi=(), sync-xhr=(), microphone=(), camera=(), magnetometer=(), gyroscope=(), fullscreen=(), payment=()" always;
proxy_hide_header "X-Frame-Options"; # Esconde header do backend para não duplicar
proxy_hide_header "Feature-Policy";
# --- Bloco de Compressão ---
brotli on;
@ -161,17 +119,6 @@ server {
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;
# --- Bloqueio de Bots e Scanners ---
if ($http_user_agent ~* (nmap|nikto|sqlmap|wpscan|python-requests|curl)) {
return 403;
}
location ~* /(\.git|\.env|\.config|composer\.json|vendor/|config\.php) {
return 404;
}
location ~* /(wp-admin|wp-login|xmlrpc\.php) {
return 404;
}
# --- Rotas Específicas Nextcloud ---
location = /.well-known/carddav { return 301 /remote.php/dav; }
location = /.well-known/caldav { return 301 /remote.php/dav; }
@ -182,7 +129,28 @@ server {
gzip on;
expires $cache_asset;
proxy_pass http://officeonline_backend;
if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' "$scheme://$http_host"; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, HEAD'; add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since, X-UserType'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Max-Age' 1728000; return 204; } add_header 'Access-Control-Allow-Origin' "$scheme://$http_host" always; add_header 'Access-Control-Allow-Credentials' 'true' always; sub_filter 'srvoffice001.itguys.com.br' 'cloud.grupopralog.com.br'; sub_filter_once off; sub_filter_types text/html text/css text/javascript application/javascript application/json; proxy_set_header Host "srvoffice001.itguys.com.br"; 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 Accept-Encoding ""; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' "$scheme://$http_host";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, HEAD';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since, X-UserType';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Max-Age' 1728000;
return 204;
}
add_header 'Access-Control-Allow-Origin' "$scheme://$http_host" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
sub_filter 'srvoffice001.itguys.com.br' 'cloud.grupopralog.com.br';
sub_filter_once off;
sub_filter_types text/html text/css text/javascript application/javascript application/json;
proxy_set_header Host "srvoffice001.itguys.com.br";
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 Accept-Encoding "";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# --- Blocos de Cache ---