[Auto-Sync] Atualização das configurações em srvproxy001.itguys.com.br - 2025-09-27 22:10:39
This commit is contained in:
parent
b1c67a4897
commit
e5752b45a8
|
|
@ -1,7 +1,7 @@
|
|||
# ==============================================================================
|
||||
# ARQUIVO: /etc/nginx/sites-available/monitoramento.itguys.com.br.conf
|
||||
# AUTOR: Gemini (Especialista NGINX)
|
||||
# DATA: 27/09/2025 (Refatorado para o Padrão do Nextcloud)
|
||||
# AUTOR: Gemini (Especialista NGINX)
|
||||
# DATA: 27/09/2025 (Refatorado para o Padrão do Nextcloud)
|
||||
#
|
||||
# CONTEXTO:
|
||||
# Configuração consolidada e segura para Proxy Reverso do Grafana.
|
||||
|
|
@ -15,157 +15,157 @@
|
|||
# UPSTREAM: Servidor Grafana
|
||||
# ------------------------------------------------------------------------------
|
||||
upstream grafana_backend {
|
||||
server 172.16.254.13:3000;
|
||||
keepalive 64;
|
||||
server 172.16.254.13:3000;
|
||||
keepalive 64;
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# BLOCO 1: Redirecionamento de HTTP (porta 80) para HTTPS
|
||||
# ------------------------------------------------------------------------------
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name monitoramento.itguys.com.br;
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name monitoramento.itguys.com.br;
|
||||
|
||||
# Aplica o rate limiting (zona global_limit deve estar em nginx.conf)
|
||||
limit_req zone=global_limit burst=20 nodelay;
|
||||
# Aplica o rate limiting (zona global_limit deve estar em nginx.conf)
|
||||
limit_req zone=global_limit burst=20 nodelay;
|
||||
|
||||
# Responde ao desafio do Let's Encrypt
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/html;
|
||||
}
|
||||
# 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;
|
||||
}
|
||||
# Redireciona todo o resto para HTTPS
|
||||
location / {
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# BLOCO 2: Servidor Principal - Proxy Reverso para Grafana (HTTPS)
|
||||
# ------------------------------------------------------------------------------
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name monitoramento.itguys.com.br;
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name monitoramento.itguys.com.br;
|
||||
|
||||
# ============================================================================
|
||||
# LOGS, LIMITAÇÃO E SEGURANÇA BÁSICA
|
||||
# ============================================================================
|
||||
client_max_body_size 10M; # Tamanho razoável para uploads do Grafana
|
||||
access_log /var/log/nginx/monitoramento.itguys.com.br.access.log combined;
|
||||
error_log /var/log/nginx/monitoramento.itguys.com.br.error.log warn;
|
||||
# Log para acessos bloqueados por bots (depende de $is_bad_bot em nginx.conf)
|
||||
access_log /var/log/nginx/monitoramento.itguys.com.br.bad-bot.log blocked if=$is_bad_bot;
|
||||
# ============================================================================
|
||||
# LOGS, LIMITAÇÃO E SEGURANÇA BÁSICA
|
||||
# ============================================================================
|
||||
client_max_body_size 10M; # Tamanho razoável para uploads do Grafana
|
||||
access_log /var/log/nginx/monitoramento.itguys.com.br.access.log combined;
|
||||
error_log /var/log/nginx/monitoramento.itguys.com.br.error.log warn;
|
||||
# Log para acessos bloqueados por bots (depende de $is_bad_bot em nginx.conf)
|
||||
access_log /var/log/nginx/monitoramento.itguys.com.br.bad-bot.log suspicious_bot if=$is_bad_bot;
|
||||
|
||||
# Módulo de Segurança Global (Bloqueia bots e URIs suspeitas de nginx.conf)
|
||||
if ($block_request) {
|
||||
return 404; # Retorna 404 de forma discreta
|
||||
}
|
||||
# Módulo de Segurança Global (Bloqueia bots e URIs suspeitas de nginx.conf)
|
||||
if ($block_request) {
|
||||
return 404; # Retorna 404 de forma discreta
|
||||
}
|
||||
|
||||
# Rate Limiting (zona global_limit deve estar em nginx.conf)
|
||||
limit_req zone=global_limit burst=100 nodelay;
|
||||
# Rate Limiting (zona global_limit deve estar em nginx.conf)
|
||||
limit_req zone=global_limit burst=100 nodelay;
|
||||
|
||||
# ============================================================================
|
||||
# CONFIGURAÇÕES DE SSL/TLS (Hardening)
|
||||
# ============================================================================
|
||||
ssl_certificate /etc/letsencrypt/live/monitoramento.itguys.com.br/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/monitoramento.itguys.com.br/privkey.pem;
|
||||
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;
|
||||
# ============================================================================
|
||||
# CONFIGURAÇÕES DE SSL/TLS (Hardening)
|
||||
# ============================================================================
|
||||
ssl_certificate /etc/letsencrypt/live/monitoramento.itguys.com.br/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/monitoramento.itguys.com.br/privkey.pem;
|
||||
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;
|
||||
|
||||
# OCSP Stapling
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
ssl_trusted_certificate /etc/letsencrypt/live/monitoramento.itguys.com.br/fullchain.pem;
|
||||
resolver 8.8.8.8 8.8.4.4 valid=300s; # Ajuste para seu DNS interno, se aplicável
|
||||
resolver_timeout 5s;
|
||||
# OCSP Stapling
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
ssl_trusted_certificate /etc/letsencrypt/live/monitoramento.itguys.com.br/fullchain.pem;
|
||||
resolver 8.8.8.8 8.8.4.4 valid=300s; # Ajuste para seu DNS interno, se aplicável
|
||||
resolver_timeout 5s;
|
||||
|
||||
# ============================================================================
|
||||
# HEADERS DE SEGURANÇA (Alinhado ao Nextcloud)
|
||||
# ============================================================================
|
||||
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=(), microphone=(), camera=(), payment=()" always;
|
||||
|
||||
# CSP - O Grafana é mais flexível que o Nextcloud, mas pode precisar de ajustes dependendo dos plugins
|
||||
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' wss:; font-src 'self'; object-src 'none';" always;
|
||||
|
||||
# Oculta headers do Grafana para aplicar o nosso
|
||||
proxy_hide_header "X-Content-Type-Options";
|
||||
proxy_hide_header "X-Frame-Options";
|
||||
proxy_hide_header "Content-Security-Policy";
|
||||
# ============================================================================
|
||||
# HEADERS DE SEGURANÇA (Alinhado ao Nextcloud)
|
||||
# ============================================================================
|
||||
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=(), microphone=(), camera=(), payment=()" always;
|
||||
|
||||
# CSP - O Grafana é mais flexível que o Nextcloud, mas pode precisar de ajustes dependendo dos plugins
|
||||
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' wss:; font-src 'self'; object-src 'none';" always;
|
||||
|
||||
# Oculta headers do Grafana para aplicar o nosso
|
||||
proxy_hide_header "X-Content-Type-Options";
|
||||
proxy_hide_header "X-Frame-Options";
|
||||
proxy_hide_header "Content-Security-Policy";
|
||||
|
||||
# ============================================================================
|
||||
# COMPRESSÃO (Alinhado ao Nextcloud)
|
||||
# ============================================================================
|
||||
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;
|
||||
# ============================================================================
|
||||
# COMPRESSÃO (Alinhado ao Nextcloud)
|
||||
# ============================================================================
|
||||
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 GLOBAIS DE PROXY (Aplicados a todas as locations por padrão)
|
||||
# ============================================================================
|
||||
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_connect_timeout 60s;
|
||||
proxy_read_timeout 90s; # Padrão para Grafana
|
||||
proxy_send_timeout 90s; # Padrão para Grafana
|
||||
proxy_buffering off; # Recomenda-se para aplicações em tempo real
|
||||
proxy_request_buffering off;
|
||||
# ============================================================================
|
||||
# PARÂMETROS GLOBAIS DE PROXY (Aplicados a todas as locations por padrão)
|
||||
# ============================================================================
|
||||
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_connect_timeout 60s;
|
||||
proxy_read_timeout 90s; # Padrão para Grafana
|
||||
proxy_send_timeout 90s; # Padrão para Grafana
|
||||
proxy_buffering off; # Recomenda-se para aplicações em tempo real
|
||||
proxy_request_buffering off;
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# ROTAS ESPECÍFICAS
|
||||
# ----------------------------------------------------------------------------
|
||||
# ----------------------------------------------------------------------------
|
||||
# ROTAS ESPECÍFICAS
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# 1. Rota para assets estáticos do Grafana (/public/) - CACHE AGRESSIVO
|
||||
location /public/ {
|
||||
proxy_pass http://grafana_backend;
|
||||
|
||||
# Cache NGINX
|
||||
# A zona 'grafana_cache' deve ser definida no seu nginx.conf
|
||||
# proxy_cache grafana_cache;
|
||||
# proxy_cache_valid 200 7d;
|
||||
# proxy_cache_valid any 1m;
|
||||
|
||||
# Headers de Cache
|
||||
expires 7d; # Alternativa simples ao proxy_cache para static assets
|
||||
add_header Cache-Control "public, immutable";
|
||||
# add_header X-Proxy-Cache $upstream_cache_status;
|
||||
}
|
||||
# 1. Rota para assets estáticos do Grafana (/public/) - CACHE AGRESSIVO
|
||||
location /public/ {
|
||||
proxy_pass http://grafana_backend;
|
||||
|
||||
# Cache NGINX
|
||||
# A zona 'grafana_cache' deve ser definida no seu nginx.conf
|
||||
# proxy_cache grafana_cache;
|
||||
# proxy_cache_valid 200 7d;
|
||||
# proxy_cache_valid any 1m;
|
||||
|
||||
# Headers de Cache
|
||||
expires 7d; # Alternativa simples ao proxy_cache para static assets
|
||||
add_header Cache-Control "public, immutable";
|
||||
# add_header X-Proxy-Cache $upstream_cache_status;
|
||||
}
|
||||
|
||||
# 2. Rota para WebSockets do Grafana (/api/live/) - SEM CACHE, LONGO TIMEOUT
|
||||
location /api/live/ {
|
||||
proxy_pass http://grafana_backend;
|
||||
|
||||
# Headers necessários para WebSockets
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 86400s; # Timeout longo (24h) para conexões live
|
||||
}
|
||||
# 2. Rota para WebSockets do Grafana (/api/live/) - SEM CACHE, LONGO TIMEOUT
|
||||
location /api/live/ {
|
||||
proxy_pass http://grafana_backend;
|
||||
|
||||
# Headers necessários para WebSockets
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 86400s; # Timeout longo (24h) para conexões live
|
||||
}
|
||||
|
||||
# 3. Rota principal para a aplicação (SEM CACHE)
|
||||
location / {
|
||||
proxy_pass http://grafana_backend;
|
||||
}
|
||||
# 3. Rota principal para a aplicação (SEM CACHE)
|
||||
location / {
|
||||
proxy_pass http://grafana_backend;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue