
Reverse Proxy for Node.js — Nginx and Apache2 Side by Side
In Part 1 , we set up NVM and PM2. In Part 2 , we started the Node.js application. Now let's put a reverse proxy in front of it. Why a Reverse Proxy? Your Node.js app should never be directly exposed on port 80 or 443. A reverse proxy handles: SSL/TLS termination — Node doesn't deal with certificates Security headers — added at the proxy layer Static file serving — offload from Node Request buffering — protects Node from slow clients Centralized access logs Both Nginx and Apache2 get the job done. Pick whichever is already in your stack. Nginx Install sudo apt update && sudo apt install -y nginx Configuration # /etc/nginx/sites-available/myapp.conf upstream node_backend { server 127.0.0.1 : 3000 ; keepalive 64 ; } server { listen 80 ; server_name myapp.example.com ; return 301 https:// $host$request_uri ; } server { listen 443 ssl http2 ; server_name myapp.example.com ; # SSL ssl_certificate /etc/letsencrypt/live/myapp.example.com/fullchain.pem ; ssl_certificate_key /etc/letsencrypt/li
Continue reading on Dev.to
Opens in a new tab



