Deploying a Custom NGINX Reverse Proxy for Your Node.js App

Learn how to set up a custom NGINX reverse proxy for your Node.js application, including SSL configuration for secure connections.

๐Ÿ“‚ Step-by-Step Server Configuration Guide

๐Ÿงญ Step 1: Navigate to the required directory

cd /etc/nginx/sites-enabled

๐Ÿงน Step 2: Delete the default configuration file

sudo rm default

โœ๏ธ Step 3: Create a new configuration file

sudo nano default

Paste the following code inside the nano editor:

server {
    listen 80;

     server_name yourdomain.com; # Replace with your domain

    location / {
        if ($host = yourdomain.com) {
            proxy_pass http://23.94.233.79:3008; # Replace with your Node.js app's port
        }

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
  • โžก๏ธ Save the file: Press CTRL + O to save, then Enter, and CTRL + X to exit nano.

โœ… Step 4: Test and restart NGINX

sudo nginx -t
sudo systemctl restart nginx

๐Ÿ” Step 5: Install Certbot for HTTPS (SSL)

sudo apt install certbot python3-certbot-nginx

๐Ÿ”’ Step 6: Obtain SSL Certificate

sudo certbot --nginx -d yourdomain.com

Now, your Node.js app should be accessible via https://yourdomain.com with a valid SSL certificate! ๐ŸŽ‰