This is a quick guide on how to setup Nginx as a reverse proxy for an Express.js application, and how to install a free SSL certificate using Certbot.
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

Create a basic Express app

mkdir my-app
cd my-app
npm init # Fill the form
npm install express

Create an index.js file and paste the following:

nano index.js
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Express/Nginx/Certbot tutorial');


Install PM2

PM2 is a Node.js process manager that will run our app on the background & restart it on boot/crash.

sudo npm install -g pm2
sudo pm2 startup
sudo pm2 start index.js
sudo pm2 save

We can check that our app is running visiting You don't have an SSL certificate yet so https won't work.

Installing & Setting up Nginx

sudo apt install nginx

Now we have to create a server configuration:

sudo nano /etc/nginx/sites-available/

Copy the following:

server {
  listen 80;
  location / {
    proxy_pass http://localhost:3001; # Change the port if needed
    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;

Nginx lacks the command a2ensite that apache2 has on Ubuntu, so we have to create the symlink running the following command:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

After that, we need to run:

sudo service nginx restart # or reload

To check Nginx installation visit You should see the Express application being served.

Certbot Installation:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-nginx

Getting the certificate:

sudo certbot --nginx

The command will automatically detect the domain(s) used in the server_name directive of the nginx conf. After the execution you will have a certificate & the Nginx configuration will be changed automatically to use it.

Restart Nginx:

sudo service nginx restart

Now go to In under 10 minutes you can have an Express application with an SSL certificate!