174 lines
7.0 KiB
Plaintext
174 lines
7.0 KiB
Plaintext
# =================================================================================================
|
|
# ARQUIVO: business.itguys.com.br
|
|
# AUTOR: Gemini (Especialista NGINX)
|
|
# DATA: 27/09/2025 - 17:22
|
|
# VERSÃO: 2.1 (Ajuste de Upload)
|
|
#
|
|
# DESCRIÇÃO:
|
|
# Adicionado bloco de location específico para tratar uploads, aplicando as regras
|
|
# de tipo de arquivo definidas no mapa global.
|
|
# =================================================================================================
|
|
|
|
# ==============================================================================
|
|
# BLOCO 0: Mapeamento de Tipos de Arquivo para Upload
|
|
# ==============================================================================
|
|
map $http_content_type $allowed_upload {
|
|
default 0; # Bloqueia tudo por padrão
|
|
|
|
# Tipos de arquivo permitidos
|
|
"text/csv" 1;
|
|
"application/pdf" 1;
|
|
"image/jpeg" 1;
|
|
"image/png" 1;
|
|
}
|
|
|
|
# ==============================================================================
|
|
# BLOCO 1: Redirecionamento de HTTP para HTTPS
|
|
# ==============================================================================
|
|
server {
|
|
if ($host = autolab.itguys.com.br) {
|
|
return 301 https://$host$request_uri;
|
|
} # managed by Certbot
|
|
|
|
|
|
if ($host = business.itguys.com.br) {
|
|
return 301 https://$host$request_uri;
|
|
} # managed by Certbot
|
|
|
|
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name business.itguys.com.br autolab.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 (HTTPS)
|
|
# ==============================================================================
|
|
server {
|
|
listen 443 ssl http2;
|
|
listen [::]:443 ssl http2;
|
|
server_name business.itguys.com.br autolab.itguys.com.br;
|
|
|
|
# --- Logs Dedicados (Padronizado) ---
|
|
access_log /var/log/nginx/business.itguys.com.br.access.log detailed_proxy;
|
|
access_log /var/log/nginx/business.itguys.com.br.bad-bot.log suspicious_bot if=$block_request;
|
|
error_log /var/log/nginx/business.itguys.com.br.error.log warn;
|
|
|
|
# --- Segurança (Integração com nginx.conf) ---
|
|
if ($block_request) {
|
|
return 404;
|
|
}
|
|
limit_req zone=global_limit burst=20 nodelay;
|
|
limit_req zone=bad_bot_limit;
|
|
client_max_body_size 512M;
|
|
|
|
# --- Configurações de SSL/TLS (Padronizado) ---
|
|
ssl_certificate /etc/letsencrypt/live/business.itguys.com.br/fullchain.pem; # managed by Certbot
|
|
ssl_certificate_key /etc/letsencrypt/live/business.itguys.com.br/privkey.pem; # managed by Certbot
|
|
ssl_trusted_certificate /etc/letsencrypt/live/business.itguys.com.br/fullchain.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_ciphers '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:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
|
|
ssl_session_tickets off;
|
|
ssl_stapling on;
|
|
ssl_stapling_verify on;
|
|
|
|
# --- Cabeçalhos de Segurança (Otimizados) ---
|
|
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 Content-Security-Policy "default-src 'self'; script-src 'self' https://cdn.jsdelivr.net; style-src 'self' https://cdn.jsdelivr.net; font-src https://cdn.jsdelivr.net; object-src 'none';" always;
|
|
|
|
# --- Otimização de Carregamento (Preconnect e Preload) ---
|
|
add_header Link "<https://cdn.jsdelivr.net>; rel=preconnect" always;
|
|
add_header Link "<https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css>; rel=preload; as=style" always;
|
|
|
|
# --- Configurações de Compressão (Brotli & Gzip) ---
|
|
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_comp_level 6;
|
|
gzip_min_length 1024;
|
|
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss image/svg+xml;
|
|
|
|
# --- Otimização de Conexão Keepalive ---
|
|
keepalive_timeout 75s;
|
|
keepalive_requests 1000;
|
|
|
|
# --- Estratégia de Cache Segura ---
|
|
set $session_cookie_name "seu_cookie_de_sessao";
|
|
proxy_cache business_cache;
|
|
add_header X-Proxy-Cache $upstream_cache_status;
|
|
proxy_cache_key "$scheme$request_method$host$request_uri$cookie_$session_cookie_name";
|
|
proxy_cache_bypass $cookie_$session_cookie_name $http_authorization;
|
|
proxy_no_cache $cookie_$session_cookie_name $http_authorization;
|
|
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
|
|
proxy_next_upstream_timeout 5s;
|
|
|
|
# --- Parâmetros de Proxy (Com Hardening Corrigido) ---
|
|
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_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_read_timeout 90s;
|
|
|
|
# --- REGRAS DE ROTEAMENTO (LOCATIONS) ---
|
|
|
|
# ==============================================================================
|
|
# NOVO BLOCO: Tratamento específico para o endpoint de Upload
|
|
# IMPORTANTE: Adapte "/api/upload/" para o caminho real da sua aplicação.
|
|
# ==============================================================================
|
|
location /api/upload/ {
|
|
# Primeiro, verifica se o tipo de arquivo é permitido
|
|
if ($allowed_upload = 0) {
|
|
# Se não for, registra em um log específico e retorna erro 415
|
|
access_log /var/log/nginx/business.itguys.com.br.upload-blocked.log;
|
|
return 415; # 415 Unsupported Media Type
|
|
}
|
|
|
|
# Se o arquivo for permitido, a requisição segue para o backend
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
proxy_pass https://172.16.121.13;
|
|
}
|
|
|
|
location ~* \.(?:css|js|mjs|svg|gif|png|jpg|jpeg|ico|webp|wasm|woff2?|ttf|eot)$ {
|
|
proxy_ignore_headers Cache-Control Expires;
|
|
proxy_cache_valid 200 60m;
|
|
proxy_cache_valid any 5m;
|
|
expires 30d;
|
|
add_header Cache-Control "public";
|
|
proxy_pass https://172.16.121.13;
|
|
}
|
|
|
|
# Uploads (arquivos estáticos do backend)
|
|
location /uploads/ {
|
|
alias /var/www/html/Ambiente_de_Testes/Oficina/Backend/business/ambiente_python/uploads;
|
|
autoindex off;
|
|
}
|
|
|
|
location / {
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
proxy_pass https://172.16.121.13;
|
|
}
|
|
|
|
error_page 500 502 503 504 /50x.html;
|
|
location = /50x.html {
|
|
root /usr/share/nginx/html;
|
|
internal;
|
|
}
|
|
}
|