Back to results for “Security”
Node.js › Cloud & DevOps

What is a reverse proxy, and why is Nginx commonly placed in front of a Node.js application in production?

Intermediate

Answer

A reverse proxy forwards client requests to backend servers -- Nginx is placed in front of Node.js to handle TLS termination, serve static files directly, provide basic load balancing, and buffer slow client connections so they can't tie up limited Node.js concurrency.
server {
  listen 443 ssl;
  location /static/ { root /var/www; }
  location / { proxy_pass http://localhost:3000; }
}
Real-world example A production API runs behind Nginx, which handles TLS certificates and serves static assets directly without involving the Node.js process at all.

Common follow-ups: How does the Node.js app read the real client IP when requests are proxied through Nginx?;What's the tradeoff of terminating TLS at Nginx versus in the Node.js process directly?