Esta nota era um monólito de referência técnica de ~1285 linhas. Em 2026-08-08 ela foi podada: o conteúdo conceitual virou o galho Nginx, com 16 notas em 3 fases sob a lente o ciclo de vida de uma request. O que permanece aqui é o material que não pertence ao galho: o relato de experiência do autor e o material de articulação em inglês, ambos preservados na íntegra.
distribuídas na seção ## Armadilhas comuns de cada nota do galho
O que mudou desde que este monólito foi escrito
Este tronco data de abril de 2026 e alguns trechos dele envelheceram. Três casos que o galho corrige, com a versão cravada: o par proxy_http_version 1.1; + proxy_set_header Connection ""; deixou de ser necessário para keepalive de upstream na 1.29.7 (o keepalive passou a vir ligado por padrão, e o padrão do proxy_http_version virou 1.1); o parâmetro http2 dentro de listen está depreciado desde a 1.25.1 em favor da diretiva http2 própria; e o ingress-nginx foi aposentado pelo Kubernetes SIG Network, sem correção de segurança desde março de 2026. O material preservado abaixo não foi alterado — é relato datado, e vale como tal.
Na prática (da minha experiência)
Nginx é meu reverse proxy default há anos. No MedEspecialista, Nginx está na frente de todos os serviços — terminando TLS, fazendo rate limiting, passando request_id para tracing, logando em JSON.
API começou a dar 504 esporadicamente. Logs do Nginx mostravam upstream timeout, mas backend estava saudável. Investigação: proxy_read_timeout 60s era o limit, e uma query lenta de relatório levava 70s em alguns casos. Fix temporário: aumentar timeout para 180s na location /reports/. Fix real: otimizar a query no backend.
Outro — rate limit quebrando requests legítimos:
Usuários reclamavam de 429 Too Many Requests. Diagnóstico: limit_req_zone $binary_remote_addr rate=10r/s era muito baixo para apps mobile fazendo prefetch. Fix: aumentar para 30r/s com burst=60 nodelay, e rate limit separado por endpoint (mais restritivo só em /login, /signup).
A lição principal: Nginx é simples em casos simples, mas tem muitas armadilhas. Read the docs (são ótimas), teste com nginx -t religiosamente, use healthchecks e rate limiting, e logue estruturado desde o dia 1.
How to explain in English
“Nginx is my default reverse proxy for pretty much any production system. It handles TLS termination, load balancing, static files, rate limiting, caching, and security headers — all with minimal resource overhead thanks to its event-driven architecture.
My baseline configuration starts with strong TLS (TLS 1.2 and 1.3 only, modern cipher suites), HSTS, security headers, gzip compression, and proper forwarded headers so the backend sees the real client IP and protocol. For reverse proxy, I always set X-Real-IP, X-Forwarded-For, X-Forwarded-Proto, Host, and X-Request-ID — the last one lets me propagate a request ID for distributed tracing.
For load balancing, round-robin is the default but I often use least_conn when backend pods have variable workloads. Health checks are passive in open-source Nginx with max_fails and fail_timeout. For active health checks and fancier load balancing, you need Nginx Plus or a different tool.
I always configure rate limiting with limit_req_zone — different zones for login, API, and general traffic. The burst parameter with nodelay handles traffic spikes gracefully. For API authentication, I use map to exempt premium keys from limits.
Logging goes structured — JSON format with $request_time, $upstream_response_time, and $request_id — makes ingesting into Elasticsearch or Loki trivial. I never run server_tokens on in production, never reload without nginx -t, and I monitor stub_status or Prometheus exporter for basic health metrics.
For WebSocket, you need proxy_http_version 1.1 and the Upgrade/Connection headers, plus long timeouts since connections stay idle. For gRPC, use grpc_pass instead of proxy_pass.
Common pitfalls I watch for: forgetting client_max_body_size so uploads fail silently with 413, proxy_read_timeout too low causing 504, missing security headers, running as root, and using if inside location blocks where it has unexpected behavior.”
Frases úteis em entrevista
“Nginx’s event-driven architecture solved the C10K problem — thousands of connections per worker with minimal memory.”
“I always pass forwarded headers so the backend sees the real client.”
“TLS 1.2 and 1.3 only, strong ciphers, HSTS, OCSP stapling — my baseline.”
“nginx -t before every reload, always.”
“Rate limiting with limit_req_zone is the first defense against abuse.”
“Structured JSON logging makes centralized logging trivial.”
“gzip_static serves pre-compressed files — zero CPU cost.”
“WebSocket needs HTTP 1.1 and Upgrade headers.”
“Passive health checks with max_fails and fail_timeout in OSS Nginx.”
“proxy_http_version 1.1 + empty Connection header for upstream keepalive.”