Cobra Forum

Plesk Panel => system admin => Topic started by: Administrator on Jan 01, 2023, 05:43 AM

Title: Wildcard Let's Encrypt SSL for One-Click LAMP
Post by: Administrator on Jan 01, 2023, 05:43 AM
Introduction

Let's Encrypt is an automated, open certificate authority that offers free TLS/SSL certificates for the public's benefit. The service is provided by the Internet Security Research Group (ISRG). This tutorial describes how to install a wildcard Let's Encrypt SSL certificate using certbot and lego on the Vultr One-Click LAMP app using Vultr DNS.

After completing this tutorial, the website will have a valid wildcard certificate, and the web server will redirect all HTTP requests to HTTPS. The lego method is preferred because certbot does not support automatic updates with Vultr DNS.

Prerequisite Steps

Make sure you have all of the following items complete before proceeding with this tutorial.

                          https://pix.cobrasoft.org/images/2023/01/01/Deploy.png
                          https://pix.cobrasoft.org/images/2023/01/01/DNS.png
                          https://pix.cobrasoft.org/images/2023/01/01/AccessControl.png
             
Install Wildcard SSL with Lego

The lego installation method allows for automatic updates. Choose this method if you plan to update your certificate before it expires each 90 days automatically.

1. Install lego.

The lego version in the Ubuntu 18.04 repository is old and does not support the DNS challenge method required for wildcard DNS.

                          Manually download from here:
           
             
Quotehttps://github.com/go-acme/lego/releases 

             Or, automatically download the latest:

             
Quote# curl -Ls https://api.github.com/repos/go-acme/lego/releases/latest | \

        grep browser_download_url | grep linux_amd64 | cut -d '"' -f 4 | \

        wget -i -

                          
Quote# tar xf lego_v*_linux_amd64.tar.gz

                          
Quote# mv lego /usr/local/sbin/

                          
Quote# lego -v

lego version 3.7.0 linux/amd64
[/list]

2. Get a new certificate.

                      
Quote# nano /usr/local/sbin/get-cert.sh
                      
Quote#!/bin/sh



    export VULTR_API_KEY=xxxx_EXAMPLE_API_KEY_xxxx



    export VULTR_HTTP_TIMEOUT=60

    export VULTR_POLLING_INTERVAL=60

    export VULTR_PROPAGATION_TIMEOUT=300

    export VULTR_TTL=300



    lego --dns vultr \

       --domains *.example.com \

       --domains example.com \

       --email admin@example.com \

       --path="/etc/letsencrypt/example.com" \

       --accept-tos run
[/list]
                                  
Quote# chmod +x /usr/local/sbin/get-cert.sh
                 
Quote# /usr/local/sbin/get-cert.sh
                 
Quote# ls -l /etc/letsencrypt/example.com/certificates/

total 16

-rw------- 1 root root 3307 May 20 14:15 _.example.com.crt

-rw------- 1 root root 1648 May 20 14:15 _.example.com.issuer.crt

-rw------- 1 root root  230 May 20 14:15 _.example.com.json

-rw------- 1 root root  288 May 20 14:15 _.example.com.key
[/list]

3. Install SSL Certificate for Apache
                                  
Quote# mv /etc/apache2/ssl/server.crt /etc/apache2/ssl/server.crt.old

# mv /etc/apache2/ssl/server.key /etc/apache2/ssl/server.key.old
                 
Quote# ln -s /etc/letsencrypt/example.com/certificates/_.example.com.crt /etc/apache2/ssl/server.crt

# ln -s /etc/letsencrypt/example.com/certificates/_.example.com.key /etc/apache2/ssl/server.key
                 
Quote# service apache2 restart

Set up automatic certificate renewal

Quote# nano /usr/local/sbin/renew-cert.sh
Quote#!/bin/sh



    export VULTR_API_KEY=xxxx_EXAMPLE_API_KEY_xxxx



    export VULTR_HTTP_TIMEOUT=60

    export VULTR_POLLING_INTERVAL=60

    export VULTR_PROPAGATION_TIMEOUT=300

    export VULTR_TTL=300



    lego --dns vultr \

       --domains *.example.com \

       --domains example.com \

       --email admin@example.com \

       --path="/etc/letsencrypt/example.com" \

       --accept-tos renew
[/list]
Quote# chmod +x /usr/local/sbin/renew-cert.sh
Quote# crontab -e
Quote5 4 * * 1 /usr/local/sbin/renew-cert.sh 2> /dev/null
[/list]

Summary
 
You have completed wildcard SSL installation using lego. Your server will automatically check the certificate each Monday and renew the certificate before it expires.

Install Wildcard SSL with Certbot

The certbot procedure is manual. Automatic renewal with certbot is not possible with Vultr DNS. If you want to renew automatically, the Lego method is preferred.

1. Install certbot

Install certbot with apt.
Quote# apt update && apt install certbot -y

2. Request Wildcard Certificate
Run certbot with the certonly and --manual options. Replace example.com with your domain. The domain is listed twice, once for the bare domain, and once for the wildcard. If you are not using the bare domain URL (https://example.com), you can omit that value and only request the wildcard.

Quote# certbot certonly --manual \

     -d *.example.com \

     -d example.com \

     -m admin@example.com \

     --preferred-challenges dns --agree-tos \

     --no-eff-email --manual-public-ip-logging-ok
The certbot wizard will print instructions to add a TXT record to your domain's DNS. For example:

Quote- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Please deploy a DNS TXT record under the name

_acme-challenge.example.com with the following value:



U5Y4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN914



Before continuing, verify the record is deployed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Press Enter to Continue

The certbot wizard will pause at this point. Do not press ENTER until you've completed the DNS steps below.

Use a web browser to:


Test that the TXT record is propagated properly. Popular ways to test the TXT record include dig and the dnschecker.org website. Replace example.com with your name in these examples:

Quote# dig +short TXT _acme-challenge.example.com

"U5Y4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN914"
Quotehttps://dnschecker.org/#TXT/_acme-challenge.example.com
In the propagation test, when you see the correct TXT record, return to the certbot wizard and press ENTER to continue. If the certificate challenge succeeds, certbot will report the location of the new certificate files.
Quote...

Cleaning up challenges



IMPORTANT NOTES:

- Congratulations! Your certificate and chain have been saved at:

/etc/letsencrypt/live/example.com/fullchain.pem

Your key file has been saved at:

/etc/letsencrypt/live/example.com/privkey.pem
[/list]

3. Install Certificate for Apache
Archive the existing Apache certificate.

Quote# mv /etc/apache2/ssl/server.crt /etc/apache2/ssl/server.crt.old

# mv /etc/apache2/ssl/server.key /etc/apache2/ssl/server.key.old

Link the Let's Encrypt certificate where Apache expects to find it.

Quote# ln -s /etc/letsencrypt/live/example.com/fullchain.pem /etc/apache2/ssl/server.crt

# ln -s /etc/letsencrypt/live/example.com/privkey.pem /etc/apache2/ssl/server.key

Restart Apache.

Quote# service apache2 restart
Using a web browser, navigate to your website, and verify the certificate is correct.

Summary
You have completed wildcard SSL installation using certbot. You will need to renew the certificate before it expires manually.