# Node.js Application Reverse Proxy # Proxies requests to Node.js/Express backend upstream nodejs_backend { server 127.0.0.1:3000; # For multiple instances (load balancing): # server 127.0.0.1:3000; # server 127.0.0.1:3001; # server 127.0.0.1:3002; keepalive 32; } server { listen 80; listen [::]:80; server_name app.example.com; # Logging access_log /var/log/nginx/app.access.log; error_log /var/log/nginx/app.error.log; # Main application proxy location / { proxy_pass http://nodejs_backend; # Preserve client information 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; # HTTP/1.1 for keepalive connections proxy_http_version 1.1; proxy_set_header Connection ""; # Timeouts (adjust based on application) proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; # Buffering proxy_buffering on; proxy_buffer_size 4k; proxy_buffers 8 4k; } # Serve static files directly (bypass Node.js) location /static/ { alias /var/www/app/static/; expires 1y; add_header Cache-Control "public, immutable"; access_log off; } # Health check endpoint (nginx responds directly) location /health { access_log off; return 200 "OK\n"; add_header Content-Type text/plain; } }