<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ssl &#8211; 安静</title>
	<atom:link href="https://llzi.cc/tag/ssl/feed/" rel="self" type="application/rss+xml" />
	<link>https://llzi.cc</link>
	<description></description>
	<lastBuildDate>Wed, 02 Oct 2024 14:06:04 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://llzi.cc/wp-content/uploads/2025/09/cropped-y2-32x32.jpg</url>
	<title>ssl &#8211; 安静</title>
	<link>https://llzi.cc</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>acme.sh 申请通配符证书</title>
		<link>https://llzi.cc/blog/998.html/</link>
					<comments>https://llzi.cc/blog/998.html/#respond</comments>
		
		<dc:creator><![CDATA[wind]]></dc:creator>
		<pubDate>Wed, 02 Oct 2024 14:06:04 +0000</pubDate>
				<category><![CDATA[博客]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[建站]]></category>
		<guid isPermaLink="false">https://kshar.cn/?p=998</guid>

					<description><![CDATA[阿里 DNS API 申请通配符证书并自动续期。
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">1.下载安装 acme.sh</h2>



<pre class="wp-block-code"><code>curl https://get.acme.sh | sh -s email=邮箱
source ~/.bashrc
#查看版本
acme.sh -v</code></pre>



<p>acme.sh默认安装在/root/.acme.sh，使用 ll -a查看</p>



<h2 class="wp-block-heading">2.获取阿里云DNS api</h2>



<p>其他云厂商 api 获取方式参考：<a href="https://github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_ali">https://github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_ali</a></p>



<p>控制台搜索“访问控制”</p>



<p>创建用户组并添加权限：AliyunDNSFullAccess</p>



<p>创建用户并勾选 Open API 调用访问，添加到刚才创建的用户组中</p>



<p>用户——认证管理——创建 AccessKey</p>



<pre class="wp-block-code"><code>#声明环境变量
export Ali_Key="AccessKey ID"
export Ali_Secret="AccessKey"</code></pre>



<p>在第一次申请证书后 <code>Ali_Key</code> 和 <code>Ali_Secret</code> 将会自动保存在 <code>~/.acme.sh/account.conf</code> 并在以后需要时重新使用。</p>



<h2 class="wp-block-heading">3.申请通配符证书</h2>



<pre class="wp-block-code"><code>acme.sh --issue --dns dns_ali -d 域名 -d *.域名</code></pre>



<p>acme会自动创建一个 cronjob, 在每天 0:00 点自动检测所有的证书, 如果快过期了, 需要更新, 则会自动更新证书。</p>



<pre class="wp-block-code"><code>crontab -l  #查看
crontab -e  #编辑</code></pre>



<h2 class="wp-block-heading">4.copy 证书</h2>



<p>生成的证书都放在安装目录下:&nbsp;<code>~/.acme.sh/</code>, 不要直接让 nginx/apache 的配置文件使用这下面的文件. 这里面的文件都是内部使用, 而且目录结构可能会变化。</p>



<p>两种方法：</p>



<p>1.将证书 copy 到自定义的目录下，在nginx/apache配置文件中引用此目录下的证书。</p>



<pre class="wp-block-code"><code>#nginx
acme.sh --install-cert -d 域名 --key-file       /blog/ssl/域名.key  --fullchain-file /blog/ssl/fullchain.cer --reloadcmd     "service nginx force-reload"

#apache
acme.sh --install-cert -d 域名 \
--cert-file      /path/to/certfile/in/apache/cert.pem  \
--key-file       /path/to/keyfile/in/apache/key.pem  \
--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem \
--reloadcmd     "service apache2 force-reload"</code></pre>



<p>2.使用软连接(推荐)</p>



<pre class="wp-block-code"><code>ln -s /root/.acme.sh/kshar.cn_ecc/fullchain.cer fullchain.cer 
ln -s /root/.acme.sh/kshar.cn_ecc/kshar.cn.key kshar.cn.key</code></pre>



<p>Nginx 的配置&nbsp;<code>ssl_certificate</code>&nbsp;使用&nbsp;<code>/etc/nginx/ssl/fullchain.cer</code>&nbsp;，而非&nbsp;<code>/etc/nginx/ssl/域名.cer</code></p>



<h2 class="wp-block-heading">5.查看已安装证书的信息</h2>



<pre class="wp-block-code"><code>acme.sh --info -d 域名</code></pre>



<h2 class="wp-block-heading">6.升级</h2>



<pre class="wp-block-code"><code>#升级acme
acme.sh --upgrade
#开启自动升级
acme.sh --upgrade --auto-upgrade
#关闭自动升级
acme.sh --upgrade --auto-upgrade  0
#更新证书
acme.sh --renew -d 域名 --force</code></pre>



<h2 class="wp-block-heading">7.更改acme的 ca 服务器</h2>



<p>acme.sh目前默认的ca服务器是zerossl，可能会出现出错：</p>



<p>Pending, The CA is processing your order, please just wait.</p>



<pre class="wp-block-code"><code>#更改acme的ca服务器为letsencrypt
acme.sh --set-default-ca --server letsencrypt</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://llzi.cc/blog/998.html/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Certbot申请ssl证书并自动续签</title>
		<link>https://llzi.cc/blog/665.html/</link>
					<comments>https://llzi.cc/blog/665.html/#respond</comments>
		
		<dc:creator><![CDATA[wind]]></dc:creator>
		<pubDate>Tue, 25 Jun 2024 09:56:58 +0000</pubDate>
				<category><![CDATA[博客]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[建站]]></category>
		<guid isPermaLink="false">https://kshar.cn/?p=665</guid>

					<description><![CDATA[Certbot 是一个由 Let's Encrypt 开发的免费开源工具，用于自动化部署和管理 SSL/TLS 证书，并使用crontab自动续期。]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">1.安装epel源与certbot</h2>



<pre class="wp-block-code"><code>yum install epel-release -y
yum -y update &amp;&amp; yum -y install certbot</code></pre>



<h2 class="wp-block-heading">2.申请证书</h2>



<p>停止nginx</p>



<pre class="wp-block-code"><code>systemctl stop nginx
certbot certonly --standalone -d 域名 --email 邮箱 --agree-tos --no-eff-email --force-renewal</code></pre>



<p>证书存放目录目录为：/etc/letsencrypt/live/</p>



<h2 class="wp-block-heading">3.编写自动续签脚本</h2>



<p>内容自行修改</p>



<pre class="wp-block-code"><code>cat auto_cert_renewal-1.sh 
# 定义证书存储目录
certs_directory="/etc/letsencrypt/live/"

days_before_expiry=5  # 设置在证书到期前几天触发续签

# 遍历所有证书文件
for cert_dir in $certs_directory*; do
    # 获取域名
    domain=$(basename "$cert_dir")

    # 忽略 README 目录
    if &#91; "$domain" = "README" ]; then
        continue
    fi

    # 输出正在检查的证书信息
    echo "检查证书过期日期： ${domain}"

    # 获取fullchain.pem文件路径
    cert_file="${cert_dir}/fullchain.pem"

    # 获取证书过期日期
    expiration_date=$(openssl x509 -enddate -noout -in "${cert_file}" | cut -d "=" -f 2-)

    # 输出证书过期日期
    echo "过期日期： ${expiration_date}"

    # 将日期转换为时间戳
    expiration_timestamp=$(date -d "${expiration_date}" +%s)
    current_timestamp=$(date +%s)

    # 计算距离过期还有几天
    days_until_expiry=$(( ($expiration_timestamp - $current_timestamp) / 86400 ))

    # 检查是否需要续签（在满足续签条件的情况下）
    if &#91; $days_until_expiry -le $days_before_expiry ]; then
        echo "证书将在${days_before_expiry}天内过期，正在进行自动续签。"

        # 停止 Nginx
        systemctl stop nginx

        # 续签证书
        certbot certonly --standalone -d $domain --email 1172338990@qq.com --agree-tos --no-eff-email --force-renewal

        # 启动 Nginx
        systemctl start nginx

        echo "证书已成功续签。"
    else
        # 若未满足续签条件，则输出证书仍然有效
        echo "证书仍然有效，距离过期还有 ${days_until_expiry} 天。"
    fi

    # 输出分隔线
    echo "--------------------------"
done</code></pre>



<p>添加执行权限并测试</p>



<pre class="wp-block-code"><code>chmod +x auto_cert_renewal-1.sh

sh auto_cert_renewal-1.sh 
检查证书过期日期： kshar.cn
过期日期： Sep 23 07:56:22 2024 GMT
证书仍然有效，距离过期还有 89 天。
--------------------------</code></pre>



<h2 class="wp-block-heading">4.设置定时任务</h2>



<pre class="wp-block-code"><code>echo "0 0 * * * cd ~ &amp;&amp; ./auto_cert_renewal-1.sh" | crontab -</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://llzi.cc/blog/665.html/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
