Free application for Let's Encrypt wildcard HTTPS certificate

Note: this tutorial is operated under centos 7. Other Linux systems are similar. Reference 1   Reference 2   Expiration renewal operation

1) The method of obtaining certificate by is recommended for wall crack
2) Increase the method of obtaining certificate through docker image

1, How works

1. Get

curl | sh

Installation succeeded as follows

Note: I have a problem with centos 7. After installation, execute, and the command is not found. If I have the same problem, please shut down the terminal and log in again, or execute the following command:

source ~/.bashrc

2. Start obtaining certificate

The power of is that it can automatically configure DNS without going to the domain name background to resolve records. My domain name is registered in Alibaba. Here is an example of Alibaba cloud resolution. For registration in other places, please refer to here for self modification: Portal

Please go to Alibaba cloud background to obtain app key and app secret Portal , and execute the following script

# Replace with the key obtained from Alibaba cloud background
export Ali_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
export Ali_Secret="jlsdflanljkljlfdsaklkjflsa"
# Change to your own domain name --issue --dns dns_ali -d -d *

This is the way to wait for DNS to take effect by thread dormancy for 120 seconds, so it needs to wait at least two minutes

At this point, it's done. Scatter flowers

The generated certificate is placed in this directory: ~ /

Here is an example of Nginx applying the certificate:

# Domain is replaced by its own domain name
server {
    listen 443 http2 ssl;
    ssl_certificate /path/;
    ssl_certificate_key /path/;
    ssl_trusted_certificate  /path/;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
} is more automatic than certbot, which saves the steps of manually changing DNS records in the background of domain name, and does not rely on Python, wall crack recommendation

After the first success, will record the app key and app secret, and generate a scheduled task to automatically detect and renew the expired domain name at 0:00 a.m. every day. If you have any concerns about this method, please be careful, but you can also delete user level scheduled tasks and clear the ~ /. folder

2, docker image acquisition

If the docker environment is installed, you can also use the docker image to obtain the certificate. You only need one line of command

docker run --rm  -it  \
  -v "$(pwd)/out":/  \
  -e Ali_Key="xxxxxx" \
  -e Ali_Secret="xxxx" \
  neilpang/  --issue --dns dns_ali -d -d *

After success, the certificate will be saved in the out folder of the current directory. You can also specify a path. Modify the first line "$(pwd)/out" to the path you want to save.

For detailed usage, please refer to: Portal

The certificate obtained is as like as two peas. The other information is referred to in mode 1.

3, certbot method to obtain certificate [not recommended] (I can use it)

1. Get certbot Auto

# download

# Make executable
chmod a+x certbot-auto

2. Start applying for certificate

# Note please change according to your domain name
./certbot-auto --server -d "*" --manual --preferred-challenges dns-01 certonly

There is no single domain name address above. If there are more than one

# Note please change according to your domain name
./certbot-auto --server -d "*" --manual --preferred-challenges dns-01 certonly

After this step is completed, some required dependencies will be downloaded. After a while, you will be prompted to enter the email, which can be used for security reminders and renewal reminders

Note that the application for wildcard certificate is subject to DNS authentication. Follow the prompts and go to the domain name background to add the corresponding DNS TXT record. After adding, do not rush to press enter, first execute dig txt to confirm whether the resolution record is effective, and then press enter to confirm

To this step, the success!!! The certificate is stored in / etc/letsencrypt/live/ /

To renew, execute certbot auto renew

When the primary domain name and *. resolve records twice, you need to add two different value s to the DNS txt

./certbot-auto --server -d "*" -d "" --manual --preferred-challenges dns-01 certonly

Here is an example of nginx applying the certificate

server {
    listen 443 http2 ssl;
    ssl on;
    ssl_certificate /etc/cert/;
    ssl_certificate_key /etc/cert/;
    ssl_trusted_certificate  /etc/cert/;

    location / {
Published 45 original articles, won praise 3, visited 20000+
Private letter follow

Tags: DNS Docker SSL CentOS

Posted on Thu, 12 Mar 2020 01:24:20 -0400 by artisticre