以下是一键生成通用泛域名证书的 Shell 脚本:

#!/bin/bash

# 安装 certbot
yum install certbot -y

# 生成证书
certbot certonly --agree-tos --email your-email@example.com --webroot -w /var/www/html/ -d ctyunai.io -d *.ctyunai.io

# 将证书拷贝到 nginx 目录
cp /etc/letsencrypt/live/ctyunai.io/fullchain.pem /etc/nginx/ssl/
cp /etc/letsencrypt/live/ctyunai.io/privkey.pem /etc/nginx/ssl/

# 配置 nginx
cat > /etc/nginx/conf.d/ctyunai.io.conf <<EOF
server {
    listen       80;
    server_name  ctyunai.io *.ctyunai.io;
    return 301 https://\$server_name\$request_uri;
}

server {
    listen       443 ssl;
    server_name  ctyunai.io *.ctyunai.io;

    ssl_certificate /etc/nginx/ssl/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/privkey.pem;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}
EOF

# 重启 nginx
systemctl restart nginx

请将 your-email@example.com 替换为您的邮箱地址,并将脚本保存为 certbot.sh 文件。然后在 CentOS7 上运行以下命令:

chmod +x certbot.sh
./certbot.sh

运行完毕后,您将拥有一个通用泛域名证书,可用于 nginx 配置。

CentOS7 主域名 ctyunaiio 生成一个通用泛域名的证书用于 nginx 配置。使用Shell脚本一键生成。

原文地址: http://www.cveoy.top/t/topic/bQQT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录