From 1a523e56dd7ba160183fcfe911dcda99178a2d41 Mon Sep 17 00:00:00 2001 From: "srvproxy001.itguys.com.br" Date: Wed, 24 Sep 2025 22:05:49 -0300 Subject: [PATCH] =?UTF-8?q?[Auto-Sync]=20Atualiza=C3=A7=C3=A3o=20das=20con?= =?UTF-8?q?figura=C3=A7=C3=B5es=20em=20srvproxy001.itguys.com.br=20-=20202?= =?UTF-8?q?5-09-24=2022:05:49?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sites-available/unifi.itguys.com.br.conf | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 nginx/sites-available/unifi.itguys.com.br.conf diff --git a/nginx/sites-available/unifi.itguys.com.br.conf b/nginx/sites-available/unifi.itguys.com.br.conf new file mode 100644 index 0000000..2de3f2b --- /dev/null +++ b/nginx/sites-available/unifi.itguys.com.br.conf @@ -0,0 +1,121 @@ +# ========================================================================================= +# ARQUIVO: /etc/nginx/sites-available/unifi.itguys.com.br.conf +# AUTOR: Gemini (Especialista NGINX) +# DATA: 25/09/2025 - 22:05 +# VERSÃO: 6.1 (Correção para erro 400 - Bad Request) +# +# DESCRIÇÃO: +# Configuração de Proxy Reverso OTIMIZADA e SEGURA para a interface UniFi. +# Esta versão ajusta os cabeçalhos do proxy para resolver o erro '400 Bad Request' +# e garantir a compatibilidade com a API e WebSockets do UniFi. +# ========================================================================================= + +# --- DEFINIÇÃO DOS BACKENDS --- +upstream unifi_backend_web { + server 172.16.254.123:8443; +} +upstream unifi_backend_inform { + server 172.16.254.123:8080; +} + +# ========================================================================================= +# BLOCO 1: Redirecionamento de HTTP (porta 80) para HTTPS +# ========================================================================================= +server { + listen 80; + listen [::]:80; + server_name unifi.itguys.com.br; + + location /.well-known/acme-challenge/ { + root /var/www/html; + } + location / { + return 301 https://$host$request_uri; + } +} + +# ========================================================================================= +# BLOCO 2: Servidor Principal - Proxy Reverso para a Interface Web (HTTPS) +# ========================================================================================= +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name unifi.itguys.com.br; + + access_log /var/log/nginx/unifi.itguys.com.br.access.log; + error_log /var/log/nginx/unifi.itguys.com.br.error.log warn; + + # ================================================================= + # INÍCIO: Configurações de SSL/TLS (Autocontido) + # ================================================================= + ssl_certificate /etc/letsencrypt/live/unifi.itguys.com.br/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/unifi.itguys.com.br/privkey.pem; + ssl_trusted_certificate /etc/letsencrypt/live/unifi.itguys.com.br/fullchain.pem; + ssl_session_timeout 1d; + ssl_session_tickets off; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_prefer_server_ciphers off; + ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384'; + ssl_stapling on; + ssl_stapling_verify on; + # ================================================================= + # FIM: Configurações de SSL/TLS + # ================================================================= + + # --- 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 X-XSS-Protection "1; mode=block" always; + add_header Referrer-Policy "no-referrer-when-downgrade" always; + add_header Content-Security-Policy "default-src 'self'; connect-src 'self' wss:; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://static.ui.com https://images.svc.ui.com; font-src 'self' data:; object-src 'none'; frame-ancestors 'self';" always; + + # --- Compressão --- + 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_proxied any; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss image/svg+xml; + + # --- ROTA PARA A APLICAÇÃO --- + location / { + proxy_pass https://unifi_backend_web; + proxy_ssl_verify off; + + # --- Cabeçalhos Essenciais para UniFi (AJUSTADOS) --- + 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; + + # --- Cabeçalhos para WebSocket --- + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_read_timeout 86400; # Timeout longo para manter a conexão + } +} + +# ============================================================================== +# BLOCO 3: Servidor para o "Inform" dos Dispositivos (HTTP na porta 8080) +# ============================================================================== +server { + listen 8080; + listen [::]:8080; + server_name unifi.itguys.com.br; + + access_log /var/log/nginx/unifi-inform.log; + error_log /var/log/nginx/unifi-inform.error.log; + + location / { + proxy_set_header Host $http_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_read_timeout 600s; + proxy_send_timeout 600s; + proxy_pass http://unifi_backend_inform; + } +}