# NGINX Configuration for Local Testing # Simula o ambiente de produção para testes locais events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # Log format log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' 'rt=$request_time uct="$upstream_connect_time" ' 'uht="$upstream_header_time" urt="$upstream_response_time"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; # Gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; # Upstream configuration para load balancing upstream bcards_backend { least_conn; server bcards-server1:8080 max_fails=3 fail_timeout=30s; server bcards-server2:8080 max_fails=3 fail_timeout=30s; keepalive 32; } # Rate limiting limit_req_zone $binary_remote_addr zone=general:10m rate=10r/s; server { listen 80; server_name localhost; # Rate limiting limit_req zone=general burst=20 nodelay; # Health check do NGINX location = /nginx-health { access_log off; return 200 "nginx ok\n"; add_header Content-Type text/plain; } # Backend health check location = /backend-health { access_log off; proxy_pass http://bcards_backend/health; proxy_connect_timeout 5s; proxy_read_timeout 5s; } # Main application proxy location / { proxy_pass http://bcards_backend; # Headers para proxy reverso 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 X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; # Timeouts proxy_connect_timeout 30s; proxy_send_timeout 30s; proxy_read_timeout 30s; # Buffer settings proxy_buffering on; proxy_buffer_size 4k; proxy_buffers 8 4k; # Retry configuration proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_next_upstream_tries 2; proxy_next_upstream_timeout 10s; } # Static files caching location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { proxy_pass http://bcards_backend; 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; expires 1h; add_header Cache-Control "public"; access_log off; } # Status page para monitoramento location = /status { access_log off; return 200 "{\n \"status\": \"ok\",\n \"timestamp\": \"$time_iso8601\",\n \"server\": \"nginx-test\"\n}"; add_header Content-Type application/json; } # Error pages error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } # Monitoring endpoint server { listen 8081; server_name localhost; location /nginx_status { stub_status on; access_log off; allow all; } } }