--- # nginx.conf events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # Logging 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; # Performance settings sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; client_max_body_size 100M; # Gzip compression gzip on; gzip_vary on; gzip_min_length 1000; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; # Rate limiting limit_req_zone $binary_remote_addr zone=upload:10m rate=10r/m; limit_req_zone $binary_remote_addr zone=api:10m rate=60r/m; upstream pdf_summarizer_backend { server pdf-summarizer-api:8000 max_fails=3 fail_timeout=30s; } server { listen 80; server_name localhost; # Security headers add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; # Frontend location / { root /usr/share/nginx/html; index index.html; try_files $uri $uri/ /index.html; } # API endpoints location /api/ { limit_req zone=api burst=20 nodelay; proxy_pass http://pdf_summarizer_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; # Timeouts proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 300s; } # Upload endpoint with special rate limiting location /api/upload { limit_req zone=upload burst=5 nodelay; proxy_pass http://pdf_summarizer_backend/upload; 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; # Extended timeouts for uploads proxy_connect_timeout 60s; proxy_send_timeout 300s; proxy_read_timeout 300s; client_max_body_size 100M; } # Health check location /health { proxy_pass http://pdf_summarizer_backend/health; access_log off; } # Static files caching location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires 1y; add_header Cache-Control "public, immutable"; } } }