How to Install Nginx with HTTPS on Ubuntu

This article explains how to install Nginx with HTTPS on Ubuntu. Install Nginx from the default repositories, configure the UFW firewall to allow SSH and Nginx HTTPS traffic, and verify the installation by checking the service status and visiting the server IP in a browser. Then configure a domain by creating a website directory, adding a sample HTML page, setting up an Nginx server block, and enabling it. Finally, install Certbot and obtain a free Let's Encrypt SSL certificate with the Nginx plugin, and confirm that automatic renewal is configured.

Prerequisites

Before starting, make sure you have:

  • An Ubuntu 20.04 or Ubuntu 22.04 server (VPS or dedicated server).
  • A non-root user with sudo privileges.
  • A domain name (optional but required for HTTPS setup).

Steps to Install Nginx on Ubuntu

Step 1: Installing Nginx on Ubuntu

Log in to your server:

ssh user_name@server_ip 

Nginx is included in Ubuntu’s default repositories. To install Nginx:

sudo apt update
sudo apt install nginx

That’s it! Nginx is now installed.

Step 2: Configuring the Firewall for Nginx

Ubuntu uses UFW (Uncomplicated Firewall). You need to allow Nginx traffic.

Check UFW status:

sudo ufw status

Enable UFW and allow SSH + Nginx HTTPS traffic:

sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 'Nginx HTTPS'
sudo ufw status

This ensures that ports 80 (HTTP) and 443 (HTTPS) are open.

Step 3: Checking Your Nginx Installation

After installation, Nginx should be running automatically. Confirm with:

systemctl status nginx

Then test in your browser:

http://your_server_ip

checking your web server
If you see the Nginx welcome page, your Nginx setup on Ubuntu is successful.
checking your web server

Step 4: Configuring Nginx for a Domain

Here are basic commands for managing Nginx:

sudo systemctl stop nginx     # Stop Nginx
sudo systemctl start nginx    # Start Nginx
sudo systemctl restart nginx  # Restart Nginx
sudo systemctl reload nginx   # Reload configs without stopping
sudo systemctl enable nginx   # Auto start at boot
sudo systemctl disable nginx  # Disable auto start

Step 5: Managing Nginx Process

By default, Nginx serves files from /var/www/html. To host multiple domains, create new server blocks.

  1. Create a website directory
sudo mkdir -p /var/www/example.com
sudo chown -R $USER:$USER /var/www/example.com
sudo chmod -R 755 /var/www/example.com
  1. Add a sample HTML page
nano /var/www/example.com/index.html

Paste:

<html>
  <head><title>Welcome to example.com!</title></head>
  <body><h1>Success! example.com is working on Nginx!</h1></body>
</html>
  1. Configure Nginx server block
sudo nano /etc/nginx/sites-available/example.com

Add:

server {
    listen 80;
    server_name example.com www.example.com;

    root /var/www/example.com;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Enable site:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Test and reload:

sudo nginx -t
sudo systemctl restart nginx

Visit http://example.com and your new site should be live.
update nginx configuration

Step 6: Install Certbot for SSL

Let’s Encrypt provides free SSL certificates. Install Certbot:

sudo apt install certbot python3-certbot-nginx

Step 7: Obtain and Install SSL Certificate

Run Certbot with the Nginx plugin:

sudo certbot --nginx -d example.com -d www.example.com

Certbot will:

  • Verify domain ownership
  • Install the SSL certificate
  • Update Nginx config automatically

Now test:

https://example.com

Your site is now secure with HTTPS.

Step 8: Auto-Renewing SSL Certificates

Let’s Encrypt certificates expire every 90 days. Certbot sets up automatic renewal with a systemd timer.
Check status:

sudo systemctl status certbot.timer

You can test renewal manually:

sudo certbot renew --dry-run

Conclusion

You’ve successfully:

  • Installed Nginx on Ubuntu
  • Configured firewall & server blocks
  • Installed and configured SSL with Let’s Encrypt
  • Enabled auto-renewal for HTTPS

Now your Ubuntu server is ready to securely serve websites using Nginx HTTPS setup.

Keywords:

setup nginx, install nginx ubuntu, instal nginx ubuntu, install and configure nginx ubuntu, install nginx in ubuntu, nginx setup ubuntu, nginx ubuntu setup, install nginx, nginx ubuntu, nginx for ubuntu, config ssl nginx, configure ssl on nginx, nginx setup ssl, ssl configuration in nginx, ssl configuration nginx, install nginx ubuntu 22.04, nginx https setup, nginx configure https, install nginx on ubuntu 22.04, let's encrypt nginx ubuntu

Last Updated:   11/13/2026
Outline