{"name":"nginx-reverse-proxy","title":"Nginx reverse proxy config","description":"An Nginx reverse proxy config for an app on port 3000 with HTTPS from Let's Encrypt, HTTP and www redirects, forwarded headers and WebSocket support.","category":"deploy","updated":"2026-11-30","url":"https://sniptide.com/templates/nginx-reverse-proxy","files":[{"name":"example.com.conf","language":"text","content":"# Reverse proxy for an app listening on 127.0.0.1:3000, with HTTPS from Let's Encrypt.\n# Save as /etc/nginx/conf.d/example.com.conf and replace example.com with your domain.\n\n# Sends Connection: upgrade only when the client asks for a WebSocket.\nmap $http_upgrade $connection_upgrade {\n    default upgrade;\n    ''      close;\n}\n\nupstream app {\n    server 127.0.0.1:3000;\n    keepalive 32;\n}\n\n# Redirect HTTP to HTTPS, but keep the path Certbot uses to renew certificates.\nserver {\n    listen 80;\n    listen [::]:80;\n    server_name example.com www.example.com;\n\n    location /.well-known/acme-challenge/ {\n        root /var/www/certbot;\n    }\n\n    location / {\n        return 301 https://example.com$request_uri;\n    }\n}\n\n# Redirect www to the bare domain.\nserver {\n    listen 443 ssl;\n    listen [::]:443 ssl;\n    http2 on;\n    server_name www.example.com;\n\n    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;\n    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;\n\n    return 301 https://example.com$request_uri;\n}\n\nserver {\n    listen 443 ssl;\n    listen [::]:443 ssl;\n    http2 on;\n    server_name example.com;\n\n    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;\n    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;\n    ssl_protocols       TLSv1.2 TLSv1.3;\n    ssl_session_cache   shared:SSL:10m;\n\n    add_header Strict-Transport-Security \"max-age=31536000\" always;\n\n    client_max_body_size 10m;\n\n    location / {\n        proxy_pass http://app;\n        proxy_http_version 1.1;\n\n        proxy_set_header Host              $host;\n        proxy_set_header X-Real-IP         $remote_addr;\n        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n        proxy_set_header Upgrade           $http_upgrade;\n        proxy_set_header Connection        $connection_upgrade;\n\n        proxy_read_timeout 60s;\n    }\n}\n"}]}