NgixProxy_Pathfinder/nginx/nginx.conf

259 lines
11 KiB
Nginx Configuration File

# ==============================================================================
# ARQUIVO DE CONFIGURAÇÃO GLOBAL NGINX (VERSÃO MINIMALISTA)
# ==============================================================================
# AUTOR: Gemini (Especialista NGINX)
# DATA DA ALTERAÇÃO: 27/09/2025
#
# --- DESCRIÇÃO ---
# Esta configuração é intencionalmente mínima. Ela define apenas as diretivas
# que, por arquitetura do NGINX, devem existir no escopo global 'http'.
# Todas as políticas de SSL, compressão, segurança e timeouts devem ser
# declaradas explicitamente em cada arquivo de configuração de site.
# ==============================================================================
# ==========================================================
# Carregamento de Módulos Globais
# ==========================================================
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_geoip2_module.so;
load_module modules/ngx_http_modsecurity_module.so;
load_module modules/ngx_http_brotli_static_module.so;
load_module modules/ngx_http_cache_purge_module.so;
load_module modules/ngx_http_upstream_fair_module.so;
load_module modules/ngx_http_echo_module.so;
load_module modules/ngx_http_headers_more_filter_module.so;
user www-data;
worker_processes auto;
worker_rlimit_nofile 65535;
pid /run/nginx.pid;
events {
worker_connections 16384;
multi_accept on;
}
http {
# --- Configurações Globais Mínimas ---
sendfile on;
tcp_nopush on;
server_tokens off; # Padrão de segurança básico
proxy_headers_hash_bucket_size 512;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_session_cache shared:SSL:60m; # Otimização de sessão SSL
# --- DEFINIÇÃO DAS ZONAS DE CACHE (OBRIGATÓRIO AQUI) ---
# Declara todas as zonas de cache disponíveis para os sites.
proxy_cache_path /var/cache/nginx/zabbix_cache levels=1:2 keys_zone=zabbix_cache:10m max_size=1g inactive=60m use_temp_path=off;
proxy_cache_path /var/cache/nginx/api_cache levels=1:2 keys_zone=api_cache:10m max_size=100m inactive=5m use_temp_path=off;
proxy_cache_path /var/cache/nginx/exchange_private_cache levels=1:2 keys_zone=exchange_private_cache:20m max_size=500m inactive=10m use_temp_path=off;
proxy_cache_path /var/cache/nginx/zammad_cache levels=1:2 keys_zone=zammad_cache:10m max_size=500m inactive=60m use_temp_path=off;
proxy_cache_path /var/cache/nginx/static_cache levels=1:2 keys_zone=static_cache:10m max_size=2g inactive=90d use_temp_path=off;
proxy_cache_path /var/cache/nginx/nextcloud_private_cache levels=1:2 keys_zone=nextcloud_private_cache:20m max_size=1g inactive=15m use_temp_path=off;
proxy_cache_path /var/cache/nginx/nextcloud_previews_cache levels=1:2 keys_zone=nextcloud_previews:20m max_size=2g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/nginx/nextcloud_cache_grupopralog levels=1:2 keys_zone=nextcloud_cache:120m max_size=10g inactive=6h use_temp_path=off;
proxy_cache_path /var/cache/nginx/nextcloud_session_cache levels=1:2 keys_zone=nextcloud_session_cache:50m max_size=500m inactive=30m use_temp_path=off;
proxy_cache_path /var/cache/nginx/foldertree_cache keys_zone=foldertree_cache:10m levels=1:2 inactive=1m max_size=100m;
proxy_cache_path /var/cache/nginx/business_cache keys_zone=business_cache:10m inactive=60m max_size=1g;
proxy_cache_path /var/cache/nginx/gitea_cache levels=1:2 keys_zone=gitea_cache:10m inactive=60m max_size=1g;
proxy_cache_path /var/cache/nginx/itguys_cache levels=1:2 keys_zone=itguys_cache:10m inactive=60m max_size=1g;
proxy_cache_path /var/cache/nginx/snipeit_cache levels=1:2 keys_zone=snipeit_cache:10m inactive=60m max_size=1g;
proxy_cache_path /var/cache/nginx/grafana_cache levels=1:2 keys_zone=grafana_cache:10m inactive=60m max_size=1g;
proxy_cache_path /var/cache/nginx/technitium_cache levels=1:2 keys_zone=technitium_cache:10m inactive=60m max_size=1g;
proxy_cache_path /var/cache/nginx/unifi_cache levels=1:2 keys_zone=unifi_cache:10m inactive=60m max_size=1g;
proxy_cache_path /var/cache/nginx/magnusbilling_cache levels=1:2 keys_zone=magnusbilling_cache:10m max_size=1g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/nginx/workspace_cache levels=1:2 keys_zone=workspace_cache:10m max_size=1g inactive=60m use_temp_path=off;
proxy_cache_path /var/cache/nginx/solucionei_cache levels=1:2 keys_zone=solucionei_cache:20m max_size=2g inactive=90d use_temp_path=off;
proxy_cache_path /var/cache/nginx/rhema_cache levels=1:2 keys_zone=rhema_cache:20m max_size=2g inactive=90d use_temp_path=off;
proxy_cache_path /var/cache/nginx/vcenter_cache levels=1:2 keys_zone=vcenter_cache:10m max_size=1g inactive=60m use_temp_path=off;
proxy_cache_path /var/cache/nginx/ferreirareal_cache levels=1:2 keys_zone=ferreirareal_cache:10m inactive=60m max_size=1g;
# --- DEFINIÇÃO DE CAPACIDADES DE SEGURANÇA (OBRIGATÓRIO AQUI) ---
# Define as 'variáveis' e 'zonas' que os sites podem usar para segurança.
map $http_user_agent $is_bad_bot {
default 0;
~*(nikto|sqlmap|wpscan|gobuster|dirbuster|feroxbuster|nessus|nmap|curl) 1;
}
map $request_uri $is_suspicious_uri {
default 0;
~*(\.env|\.git|/vendor/|/setup\.php|/\.well-known/|/phpmyadmin|/config\.php|composer\.json) 1;
}
map $is_bad_bot$is_suspicious_uri $block_request {
default 0;
~1 1;
}
geo $is_internal {
default 0;
10.10.0.0/16 1; 10.11.0.0/16 1; 10.12.0.0/16 1; 172.16.0.0/16 1;
45.169.73.155 1; 201.73.213.130 1; 177.74.160.17 1; 177.74.160.18 1;
177.74.160.19 1; 177.74.160.20 1; 177.74.160.21 1; 177.74.160.22 1;
177.74.160.23 1; 45.169.87.168 1; 45.169.87.169 1; 45.169.87.170 1;
45.169.87.171 1; 45.169.87.172 1; 45.169.87.173 1; 45.169.87.174 1;
45.169.87.175 1; 45.169.73.154 1; 201.73.213.129 1;
}
map $is_internal $limit_key {
0 $binary_remote_addr;
1 "";
}
map $is_bad_bot $bad_bot_key {
1 $binary_remote_addr;
default "";
}
map $request_uri $cache_asset {
~*\.(css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff|woff2|ttf|otf)$ 1y;
default off;
}
limit_req_zone $limit_key zone=global_limit:20m rate=10r/s;
limit_req_zone $bad_bot_key zone=bad_bot_limit:10m rate=5r/m;
# --- ATIVAÇÃO GLOBAL DO WAF (MODSECURITY) ---
modsecurity on;
modsecurity_rules_file /etc/nginx/modsecurity.conf;
# --- CONFIGURAÇÃO DO MÓDULO GEOIP2 ---
# Carrega o banco de dados GeoIP e mapeia as variáveis usadas no log.
# Carrega o banco de dados de Cidades/Países
geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {
$geoip2_continent_code;
$geoip2_country_code;
$geoip2_country_name;
$geoip2_state_code;
$geoip2_state_name;
$geoip2_city_name;
$geoip2_postal_code;
$geoip2_latitude;
$geoip2_longitude;
$geoip2_timezone;
}
# Carrega o banco de dados de Provedor (ASN)
geoip2 /usr/share/GeoIP/GeoLite2-ASN.mmdb {
$geoip2_asn;
$geoip2_isp;
}
# --- DEFINIÇÃO DO FORMATO DE LOG (OBRIGATÓRIO AQUI) ---
# Define um formato de log rico que pode ser chamado por qualquer site.
log_format detailed_proxy escape=json
'{'
# Timestamps e Identificadores
'"@timestamp":"$time_iso8601",'
'"time_local":"$time_local",'
'"msec":"$msec",'
'"request_id":"$request_id",'
'"hostname":"$hostname",'
'"worker_pid":$pid,'
# Informações de Conexão e Cliente
'"remote_addr":"$remote_addr",'
'"remote_port":$remote_port,'
'"server_addr":"$server_addr",'
'"server_port":"$server_port",'
'"real_ip":"$http_x_forwarded_for",'
'"http_x_real_ip":"$http_x_real_ip",'
'"remote_user":"$remote_user",'
# Detalhes da Requisição HTTP
'"request":"$request",'
'"request_method":"$request_method",'
'"scheme":"$scheme",'
'"server_protocol":"$server_protocol",'
'"host_header":"$host",'
'"request_uri":"$request_uri",'
'"uri":"$uri",'
'"document_uri":"$document_uri",'
'"args":"$args",'
'"query_string":"$query_string",'
'"request_length":$request_length,'
# Caminhos de Arquivo no Servidor
'"document_root":"$document_root",'
'"realpath_root":"$realpath_root",'
'"request_filename":"$request_filename",'
# Headers da Requisição
'"http_referer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"http_cookie":"$http_cookie",'
'"http_accept_encoding":"$http_accept_encoding",'
'"http_accept_language":"$http_accept_language",'
# Detalhes da Resposta
'"status":$status,'
'"body_bytes_sent":$body_bytes_sent,'
'"bytes_sent":$bytes_sent,'
'"sent_http_server":"$sent_http_server",'
'"sent_http_date":"$sent_http_date",'
'"sent_http_location":"$sent_http_location",'
'"sent_http_content_type":"$sent_http_content_type",'
'"sent_http_content_encoding":"$sent_http_content_encoding",'
'"sent_http_cache_control":"$sent_http_cache_control",'
'"sent_http_content_security_policy":"$sent_http_content_security_policy",'
'"sent_http_x_frame_options":"$sent_http_x_frame_options",'
# Performance e Conexão
'"request_time":$request_time,'
'"pipe":"$pipe",'
'"connection":"$connection",'
'"connection_requests":$connection_requests,'
'"limit_rate":"$limit_rate",'
# SSL/TLS
'"ssl_protocol":"$ssl_protocol",'
'"ssl_cipher":"$ssl_cipher",'
'"ssl_session_id":"$ssl_session_id",'
'"ssl_server_name":"$ssl_server_name",'
'"ssl_session_reused":"$ssl_session_reused",'
'"ssl_client_verify":"$ssl_client_verify",'
# Upstream (versão ultra compatível)
'"upstream_addr":"$upstream_addr",'
'"upstream_status":"$upstream_status",'
'"upstream_connect_time":"$upstream_connect_time",'
'"upstream_header_time":"$upstream_header_time",'
'"upstream_response_time":"$upstream_response_time",'
'"upstream_response_length":$upstream_response_length,'
'"upstream_cache_status":"$upstream_cache_status",'
# Compressão
'"compression_ratio":"$gzip_ratio",'
# Módulo GeoIP2 (Expandido)
'"geoip_continent_code":"$geoip2_continent_code",'
'"geoip_country_code":"$geoip2_country_code",'
'"geoip_country_name":"$geoip2_country_name",'
'"geoip_state_code":"$geoip2_state_code",'
'"geoip_state_name":"$geoip2_state_name",'
'"geoip_city_name":"$geoip2_city_name",'
'"geoip_postal_code":"$geoip2_postal_code",'
'"geoip_latitude":$geoip2_latitude,'
'"geoip_longitude":$geoip2_longitude,'
'"geoip_timezone":"$geoip2_timezone",'
'"geoip_asn":$geoip2_asn,'
'"geoip_isp":"$geoip2_isp",'
# Variáveis Customizadas (do seu nginx.conf)
'"is_bad_bot":"$is_bad_bot",'
'"is_suspicious_uri":"$is_suspicious_uri",'
'"block_request":"$block_request",'
'"is_internal_ip":"$is_internal",'
'"rate_limit_key":"$limit_key",'
'"bad_bot_rate_limit_key":"$bad_bot_key",'
'"cacheable_asset_ttl":"$cache_asset"'
'}';
log_format suspicious_bot 'SUSPICIOUS_BOT: $remote_addr - "$http_user_agent" - "$request"';
# --- LOGS GLOBAIS DE FALLBACK ---
# Logs mínimos para requisições que não correspondem a nenhum 'server' block.
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log;
# --- Inclusão dos Arquivos de Configuração de Sites ---
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}