[Auto-Sync] Atualização das configurações em srvproxy001.itguys.com.br - 2025-09-21 20:46:44
This commit is contained in:
parent
175da4469f
commit
4ea1c8f838
|
|
@ -1,128 +0,0 @@
|
||||||
# ==============================================================================
|
|
||||||
# ARQUIVO: /etc/nginx/sites-available/unifi.itguys.com.br.conf (VERSÃO FINAL)
|
|
||||||
# AUTOR: Gemini (Especialista NGINX)
|
|
||||||
# DATA: 21/09/2025
|
|
||||||
#
|
|
||||||
# DESCRIÇÃO:
|
|
||||||
# Configuração UNIFICADA para UniFi Controller, usando um único location / com
|
|
||||||
# cache condicional para máxima compatibilidade e performance.
|
|
||||||
#
|
|
||||||
# ESTRATÉGIA:
|
|
||||||
# - Um único `location /` trata todas as requisições da UI para evitar conflitos.
|
|
||||||
# - Todos os cabeçalhos necessários (API, WebSocket) são aplicados a tudo.
|
|
||||||
# - O cache é ATIVADO por padrão, mas DESATIVADO condicionalmente para
|
|
||||||
# rotas dinâmicas e métodos de requisição que não sejam GET.
|
|
||||||
# ==============================================================================
|
|
||||||
|
|
||||||
# Define o backend da interface web do UniFi (HTTPS).
|
|
||||||
upstream unifi_backend_web {
|
|
||||||
server 172.16.254.123:8443;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Define o backend da porta "inform" do UniFi (HTTP).
|
|
||||||
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;
|
|
||||||
|
|
||||||
# --- CONFIGURAÇÕES DE SSL E SEGURANÇA ---
|
|
||||||
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
|
|
||||||
include /etc/nginx/snippets/ssl_params.conf;
|
|
||||||
add_header X-Content-Type-Options "nosniff" always;
|
|
||||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
||||||
|
|
||||||
# --- POLÍTICAS DE ACESSO E LOGS ---
|
|
||||||
include /etc/nginx/snippets/internal_networks.conf;
|
|
||||||
include /etc/nginx/snippets/global_robots.conf;
|
|
||||||
access_log /var/log/nginx/unifi.itguys.com.br.access.log;
|
|
||||||
error_log /var/log/nginx/unifi.itguys.com.br.error.log warn;
|
|
||||||
|
|
||||||
# --- PARÂMETROS DE PROXY GLOBAIS ---
|
|
||||||
include /etc/nginx/snippets/proxy_params.conf;
|
|
||||||
proxy_ssl_verify off;
|
|
||||||
|
|
||||||
# --- ROTA UNIFICADA PARA TODA A APLICAÇÃO ---
|
|
||||||
location / {
|
|
||||||
# --- LÓGICA DE CACHE CONDICIONAL ---
|
|
||||||
# Por padrão, o cache está ativo. As regras abaixo definem quando NÃO usar o cache.
|
|
||||||
set $do_not_cache 0;
|
|
||||||
|
|
||||||
# Não cacheia requisições que não sejam GET ou HEAD.
|
|
||||||
if ($request_method !~ ^(GET|HEAD)$) {
|
|
||||||
set $do_not_cache 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Não cacheia as rotas dinâmicas da aplicação.
|
|
||||||
if ($request_uri ~* "^/(api|wss|manage|v2|proxy)") {
|
|
||||||
set $do_not_cache 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy_no_cache $do_not_cache;
|
|
||||||
proxy_cache_bypass $do_not_cache;
|
|
||||||
|
|
||||||
# Configurações de cache para o que for permitido cachear (assets estáticos).
|
|
||||||
proxy_cache unifi_cache;
|
|
||||||
proxy_cache_valid 200 7d;
|
|
||||||
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
|
|
||||||
add_header X-Proxy-Cache $upstream_cache_status;
|
|
||||||
|
|
||||||
# --- CABEÇALHOS DE PROXY UNIFICADOS ---
|
|
||||||
# Cabeçalhos para WebSockets (ignorados por requisições normais).
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
|
|
||||||
# Cabeçalho para corrigir o erro "403 Forbidden" na API.
|
|
||||||
proxy_set_header X-Csrf-Token $cookie_csrf_token;
|
|
||||||
|
|
||||||
# --- PROXY PASS ---
|
|
||||||
proxy_pass https://unifi_backend_web;
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- Páginas de Erro Personalizadas ---
|
|
||||||
include /etc/nginx/snippets/custom_errors.conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
# ==============================================================================
|
|
||||||
# BLOCO 3: Servidor para o "Inform" dos Dispositivos (HTTP na porta 8080)
|
|
||||||
# ==============================================================================
|
|
||||||
server {
|
|
||||||
listen 8080;
|
|
||||||
listen [::]:8080;
|
|
||||||
server_name unifi.itguys.com.br;
|
|
||||||
|
|
||||||
include /etc/nginx/snippets/internal_networks.conf;
|
|
||||||
access_log /var/log/nginx/unifi-inform.log;
|
|
||||||
error_log /var/log/nginx/unifi-inform.error.log;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
include /etc/nginx/snippets/proxy_params.conf;
|
|
||||||
proxy_read_timeout 600s;
|
|
||||||
proxy_send_timeout 600s;
|
|
||||||
proxy_pass http://unifi_backend_inform;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue