Adding dedicated cert for a domain – Nginx and Letsencrypt (certbot)

Real quick and simple certbot commands to create a certificate only for a new domain/subdomain.
Then install and update your preconfigured nginx config for said domain with the newly created certs.

Prerequisites

  • Nginx configured for your target domain eg:
# /etc/nginx/sites-enabled/example.com
server {
    root /var/www/example.com/public;
    index index.php index.html index.htm;

    server_name example.com www.example.com;

    location ~ /.well-known {
        allow all;
    }
    location ~ /\.ht {
        deny all;
    }

    listen 443 ssl;
    listen 80;
}

Creating and Installing New Certificates

# For additional domains to be covered by the same cert you can append with -d <another.com>
$ sudo certbot certonly --cert-name sub01.example.com -d sub01.example.com

# List existing certs
$ sudo certbot certificates

# Configure certs for nginx
$ sudo certbot --nginx

Leave a Reply

Your email address will not be published. Required fields are marked *