[Auto-Sync] Atualização das configurações em srvproxy001.itguys.com.br - 2025-09-21 20:35:51
This commit is contained in:
parent
e431eb9982
commit
bca0fb0af7
|
|
@ -3,18 +3,15 @@
|
||||||
# AUTOR: Gemini (Especialista NGINX)
|
# AUTOR: Gemini (Especialista NGINX)
|
||||||
# DATA: 21/09/2025
|
# DATA: 21/09/2025
|
||||||
#
|
#
|
||||||
# DESCRICAO:
|
# DESCRIÇÃO:
|
||||||
# Configuracao de Proxy Reverso OTIMIZADA e SEGURA para UniFi Controller.
|
# Configuração CORRIGIDA para UniFi Controller, com foco em resolver erros 403
|
||||||
|
# e problemas de interface.
|
||||||
#
|
#
|
||||||
# FUNCIONALIDADES:
|
# CORREÇÕES:
|
||||||
# - Bloco 1: Redirecionamento de HTTP (porta 80) para HTTPS.
|
# - Adicionado o cabeçalho "X-Csrf-Token" para compatibilidade com a API do UniFi.
|
||||||
# - Bloco 2: Proxy para a Interface Web (HTTPS na 443 -> HTTPS na 8443)
|
# - Criada uma location dedicada para WebSockets (/wss/) para maior estabilidade.
|
||||||
# - Suporte a WebSockets para a UI em tempo real.
|
# - Removido o cache temporariamente para garantir a funcionalidade.
|
||||||
# - Cache para assets estaticos da interface.
|
# - Bloco de redirecionamento HTTP simplificado.
|
||||||
# - Lida com o certificado autoassinado do backend UniFi.
|
|
||||||
# - Bloco 3: Proxy para o "Inform" dos Dispositivos (HTTP na 8080 -> HTTP na 8080)
|
|
||||||
# - Permite que APs e Switches se comuniquem com o controlador atraves do proxy.
|
|
||||||
# - Acesso restrito a rede interna em todas as portas.
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
# Define o backend da interface web do UniFi (HTTPS).
|
# Define o backend da interface web do UniFi (HTTPS).
|
||||||
|
|
@ -31,26 +28,16 @@ upstream unifi_backend_inform {
|
||||||
# BLOCO 1: Redirecionamento de HTTP (porta 80) para HTTPS
|
# BLOCO 1: Redirecionamento de HTTP (porta 80) para HTTPS
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
server {
|
server {
|
||||||
if ($host = unifi.itguys.com.br) {
|
|
||||||
return 301 https://$host$request_uri;
|
|
||||||
} # managed by Certbot
|
|
||||||
|
|
||||||
|
|
||||||
listen 80;
|
listen 80;
|
||||||
listen [::]:80;
|
listen [::]:80;
|
||||||
server_name unifi.itguys.com.br;
|
server_name unifi.itguys.com.br;
|
||||||
|
|
||||||
# Permite a validacao do Let's Encrypt.
|
|
||||||
location /.well-known/acme-challenge/ {
|
location /.well-known/acme-challenge/ {
|
||||||
root /var/www/html;
|
root /var/www/html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Redireciona todo o trafego web para a versao segura.
|
|
||||||
location / {
|
location / {
|
||||||
return 301 https://$host$request_uri;
|
return 301 https://$host$request_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
@ -61,45 +48,47 @@ server {
|
||||||
listen [::]:443 ssl http2;
|
listen [::]:443 ssl http2;
|
||||||
server_name unifi.itguys.com.br;
|
server_name unifi.itguys.com.br;
|
||||||
|
|
||||||
# --- CONFIGURACOES DE SSL E SEGURANCA ---
|
# --- CONFIGURAÇÕES DE SSL E SEGURANÇA ---
|
||||||
ssl_certificate /etc/letsencrypt/live/unifi.itguys.com.br/fullchain.pem; # managed by Certbot
|
ssl_certificate /etc/letsencrypt/live/unifi.itguys.com.br/fullchain.pem; # managed by Certbot
|
||||||
ssl_certificate_key /etc/letsencrypt/live/unifi.itguys.com.br/privkey.pem; # managed by Certbot
|
ssl_certificate_key /etc/letsencrypt/live/unifi.itguys.com.br/privkey.pem; # managed by Certbot
|
||||||
include /etc/nginx/snippets/ssl_params.conf;
|
include /etc/nginx/snippets/ssl_params.conf;
|
||||||
add_header X-Content-Type-Options "nosniff" always;
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
|
||||||
# --- POLITICAS DE ACESSO E LOGS ---
|
# --- POLÍTICAS DE ACESSO E LOGS ---
|
||||||
include /etc/nginx/snippets/internal_networks.conf;
|
include /etc/nginx/snippets/internal_networks.conf;
|
||||||
include /etc/nginx/snippets/global_robots.conf;
|
include /etc/nginx/snippets/global_robots.conf;
|
||||||
access_log /var/log/nginx/unifi.itguys.com.br.access.log;
|
access_log /var/log/nginx/unifi.itguys.com.br.access.log;
|
||||||
error_log /var/log/nginx/unifi.itguys.com.br.error.log warn;
|
error_log /var/log/nginx/unifi.itguys.com.br.error.log warn;
|
||||||
|
|
||||||
# --- PARAMETROS DE PROXY GLOBAIS ---
|
# --- PARÂMETROS DE PROXY GLOBAIS ---
|
||||||
include /etc/nginx/snippets/proxy_params.conf;
|
include /etc/nginx/snippets/proxy_params.conf;
|
||||||
proxy_ssl_verify off;
|
proxy_ssl_verify off;
|
||||||
|
|
||||||
# --- REGRAS DE ROTEAMENTO (LOCATIONS) ---
|
# --- REGRAS DE ROTEAMENTO (LOCATIONS) ---
|
||||||
|
|
||||||
# Rota Unica para a aplicacao (SEM CACHE, COM WEBSOCKETS).
|
# 1. Rota para WebSockets (essencial para a UI em tempo real)
|
||||||
# Esta regra centralizada garante que todos os requests, incluindo assets,
|
location /wss/ {
|
||||||
# sejam enviados corretamente para o backend do UniFi.
|
|
||||||
location / {
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
|
proxy_pass https://unifi_backend_web;
|
||||||
|
}
|
||||||
|
|
||||||
# Cabecalhos essenciais para o proxy funcionar corretamente com o UniFi
|
# 2. Rota principal para a aplicação (com a correção do CSRF)
|
||||||
proxy_set_header Authorization "";
|
location / {
|
||||||
proxy_set_header Host $host;
|
# **ESTA LINHA É A CORREÇÃO PRINCIPAL PARA O ERRO 403**
|
||||||
|
# Repassa o cookie de segurança do UniFi como um cabeçalho.
|
||||||
|
proxy_set_header X-Csrf-Token $cookie_csrf_token;
|
||||||
|
|
||||||
proxy_pass https://unifi_backend_web;
|
proxy_pass https://unifi_backend_web;
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Paginas de Erro Personalizadas ---
|
# --- Páginas de Erro Personalizadas ---
|
||||||
include /etc/nginx/snippets/custom_errors.conf;
|
include /etc/nginx/snippets/custom_errors.conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# BLOCO 3: Servidor para o "Inform" dos Dispositivos (HTTP na porta 8080)
|
# BLOCO 3: Servidor para o "Inform" dos Dispositivos (HTTP na porta 8080)
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
@ -108,19 +97,14 @@ server {
|
||||||
listen [::]:8080;
|
listen [::]:8080;
|
||||||
server_name unifi.itguys.com.br;
|
server_name unifi.itguys.com.br;
|
||||||
|
|
||||||
# --- POLITICAS DE ACESSO E LOGS ---
|
|
||||||
include /etc/nginx/snippets/internal_networks.conf;
|
include /etc/nginx/snippets/internal_networks.conf;
|
||||||
access_log /var/log/nginx/unifi-inform.log;
|
access_log /var/log/nginx/unifi-inform.log;
|
||||||
error_log /var/log/nginx/unifi-inform.error.log;
|
error_log /var/log/nginx/unifi-inform.error.log;
|
||||||
|
|
||||||
# --- Rota para o /inform ---
|
|
||||||
location / {
|
location / {
|
||||||
include /etc/nginx/snippets/proxy_params.conf;
|
include /etc/nginx/snippets/proxy_params.conf;
|
||||||
|
|
||||||
# Timeouts mais longos para suportar provisionamento e atualizacoes de firmware.
|
|
||||||
proxy_read_timeout 600s;
|
proxy_read_timeout 600s;
|
||||||
proxy_send_timeout 600s;
|
proxy_send_timeout 600s;
|
||||||
|
|
||||||
proxy_pass http://unifi_backend_inform;
|
proxy_pass http://unifi_backend_inform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue