Ubuntu 使用 certbot 免费生成 HTTPS 证书

Start Nginx


sudo apt install nginx -y

sudo nginx

Configuration

sudo vim /etc/nginx/nginx.conf#server_names_hash_bucket_size 64 改为server_names_hash_bucket_size 128(一般在24行)。

需将域名test.cpchain.org修改为自己的域名


sudo su

export DOMAIN="test.cpchain.com"

cat > /etc/nginx/conf.d/$DOMAIN.conf << EOF
server {
    listen 80;
    server_name $DOMAIN;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}
server {
    listen 443 ssl;
    server_name $DOMAIN;

    location / {
        root html;
    }
}
EOF

exit

sudo nginx -s reload

Certbot


sudo add-apt-repository ppa:certbot/certbot

sudo apt update

sudo apt install python-certbot-nginx -y

sudo apt install certbot -y

export DOMAIN="test.cpchain.com"

sudo certbot --nginx -d $DOMAIN

renew


sudo certbot renew