events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log warn; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # Upstream para Node.js app upstream tudo_aqui_app { server app:3000; keepalive 32; } # Rate limiting zones # API geral: 10 requisições por segundo por IP limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; # Autenticação: 5 requisições por minuto por IP (proteção contra brute-force) limit_req_zone $binary_remote_addr zone=auth:10m rate=5r/m; # Redirect HTTP para HTTPS server { listen 80; server_name api.tudoaqui.ao tudoaqui.ao www.tudoaqui.ao; return 301 https://$server_name$request_uri; } # HTTPS com SSL/TLS server { listen 443 ssl http2; server_name api.tudoaqui.ao; # Certificado SSL (auto-signed ou Let's Encrypt) ssl_certificate /etc/nginx/ssl/certificado.crt; ssl_certificate_key /etc/nginx/ssl/chave.key; # Protocolos TLS (desabilita TLS 1.0 e 1.1 por segurança) ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; # Security headers 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 "strict-origin-when-cross-origin" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'" always; # Gzip compression gzip on; gzip_vary on; gzip_proxied any; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json; gzip_disable "msie6"; # Rate limiting padrão limit_req zone=api burst=20 nodelay; # Autenticação - rate limiting apertado location ~ ^/api/v1/auth/(register|login|verificar-telefone) { limit_req zone=auth burst=5 nodelay; proxy_pass http://tudo_aqui_app; proxy_http_version 1.1; 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; proxy_set_header Connection ""; } # API - rate limiting padrão location /api { limit_req zone=api burst=20 nodelay; proxy_pass http://tudo_aqui_app; proxy_http_version 1.1; 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; proxy_set_header Connection ""; } # Arquivos estáticos - cache agressivo location /uploads { alias /app/uploads; expires 1y; add_header Cache-Control "public, immutable" always; access_log off; } # Health check (sem logs) location /health { proxy_pass http://tudo_aqui_app/health; access_log off; } # Deny access to hidden files location ~ /\. { deny all; access_log off; log_not_found off; } } }