<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>雾非雾 - 证书</title>
<link>https://www.941741.xyz/tag/%E8%AF%81%E4%B9%A6/</link>
<atom:link href="https://www.941741.xyz/feed/tag/%E8%AF%81%E4%B9%A6/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Fri, 07 Oct 2022 10:47:00 +0800</lastBuildDate>
<pubDate>Fri, 07 Oct 2022 10:47:00 +0800</pubDate>
<item>
<title>SSL证书的申请</title>
<link>https://www.941741.xyz/archives/8.html</link>
<guid>https://www.941741.xyz/archives/8.html</guid>
<pubDate>Fri, 07 Oct 2022 10:47:00 +0800</pubDate>
<dc:creator>花非花</dc:creator>
<category><![CDATA[应用技巧]]></category>
<description><![CDATA[昨天折腾了一通，主站的 SSL 搞定了；但是子目录 php 竟然无法运行，只好暂时终止。今天来折腾了一下这个子域名，顺便记录一下申请过程。1、先安装 acme.sh登录 SSH 后，切换到 ro...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>昨天折腾了一通，主站的 SSL 搞定了；但是子目录 php 竟然无法运行，只好暂时终止。<br>今天来折腾了一下这个子域名，顺便记录一下申请过程。</p><p>1、先安装 acme.sh<br>登录 SSH 后，切换到 root 帐号<br>后面的 email 换成自己的邮箱地址</p><pre><code>curl https://get.acme.sh | sh -s email=申请用的电子邮箱</code></pre><p>安装完成后，要重启加载一下；或者关闭 SSH 重新登录一下</p><pre><code>source ~/.bashrc</code></pre><p>如果想保持 acme.sh 为最新，可开启自动更新</p><pre><code>acme.sh --upgrade --auto-upgrade</code></pre><p>2、创建用于存放证书的目录</p><pre><code>mkdir -p /var/www/letsencrypt</code></pre><p>3、acme.sh 支持 Let's Encrypt、Buypass、ZeroSSL 和 SSL.com，默认使用 ZeroSSL，切换命令：<br>Let's Encrypt</p><pre><code>acme.sh --set-default-ca --server letsencrypt</code></pre><p>Buypass</p><pre><code>acme.sh --set-default-ca --server buypass</code></pre><p>SSL.com</p><pre><code>acme.sh --set-default-ca --server ssl.com</code></pre><p>ZeroSSL</p><pre><code>acme.sh --set-default-ca --server zerossl</code></pre><p>4、配置 Nginx，用 HTTP 来验证证书签发<br>域名、验证目录根据自己需求自定义</p><pre><code>server {
    listen 80;
    listen [::]:80;
    server_name 自己的域名;
    location /.well-known/acme-challenge {
        # 自己定义的位置，用于校验服务器所有权
    root /www/wwwroot/809022.xyz;
        # 自己的网站目录
    }

    location / {
        rewrite    ^/(.*)$ https://$host/$1 permanent;
    }
}</code></pre><p>5、申请证书<br>--webroot 申请网站的根目录</p><pre><code>acme.sh --issue -d 自己的域名 --webroot /www/wwwroot/rj.809022.xyz</code></pre><p>如果有多个域名，之间用空格隔开；至于是不是支持泛域名，请自己 google</p><pre><code>acme.sh --issue -d 域名1 -d 域名2 -w /www/wwwroot/rj.809022.xyz</code></pre><p>6、申请成功后显示</p><pre><code>[root@80smus ~]# acme.sh --issue -d rj.809022.xyz --webroot /www/wwwroot/rj.809022.xyz
[Thu Oct  6 16:59:46 CST 2022] Using CA: https://acme-v02.api.letsencrypt.org/directory
[Thu Oct  6 16:59:46 CST 2022] Single domain=&#039;rj.809022.xyz&#039;
[Thu Oct  6 16:59:46 CST 2022] Getting domain auth token for each domain
[Thu Oct  6 17:00:09 CST 2022] Getting webroot for domain=&#039;rj.809022.xyz&#039;
[Thu Oct  6 17:00:09 CST 2022] Verifying: rj.809022.xyz
[Thu Oct  6 17:00:12 CST 2022] Pending, The CA is processing your order, please just wait. (1/30)
[Thu Oct  6 17:00:17 CST 2022] Success
[Thu Oct  6 17:00:17 CST 2022] Verify finished, start to sign.
[Thu Oct  6 17:00:17 CST 2022] Lets finalize the order.
[Thu Oct  6 17:00:17 CST 2022] Le_OrderFinalize=&#039;https://acme-v02.api.letsencrypt.org/acme/finalize/762972326/132022859836&#039;
[Thu Oct  6 17:00:21 CST 2022] Downloading cert.
[Thu Oct  6 17:00:21 CST 2022] Le_LinkCert=&#039;https://acme-v02.api.letsencrypt.org/acme/cert/03763b64c7f5f1a8cf1c65c70af0f87700d2&#039;
[Thu Oct  6 17:00:24 CST 2022] Cert success.
-----BEGIN CERTIFICATE-----
这里显示的是密钥
-----END CERTIFICATE-----
[Thu Oct  6 17:00:24 CST 2022] Your cert is in: /root/.acme.sh/rj.809022.xyz/rj.809022.xyz.cer
[Thu Oct  6 17:00:24 CST 2022] Your cert key is in: /root/.acme.sh/rj.809022.xyz/rj.809022.xyz.key
[Thu Oct  6 17:00:24 CST 2022] The intermediate CA cert is in: /root/.acme.sh/rj.809022.xyz/ca.cer
[Thu Oct  6 17:00:24 CST 2022] And the full chain certs is there: /root/.acme.sh/rj.809022.xyz/fullchain.cer</code></pre><p>7、安装申请到的证书<br>从上面返回的信息判断证书的保存目录在 /root/.acme.sh/rj.809022.xyz/<br>一般不推荐证书放到 root 目录使用，所以新建个目录把证书 cer key 复制过去（或者在网站根目录下建立 cert 目录用于存放：</p><pre><code>mkdir -p /www/nginx/ssl
cp /root/.acme.sh/rj.809022.xyz/rj.809022.xyz.cer /www/nginx/ssl/rj.809022.xyz.cer
cp /root/.acme.sh/rj.809022.xyz/rj.809022.xyz.key /www/nginx/ssl/rj.809022.xyz.key</code></pre><p>听说安卓手机验证可能会有问题，所以运行一下下面的命令</p><pre><code>acme.sh --installcert -d rj.809022.xyz --keypath /www/nginx/ssl/rj.809022.xyz.key --fullchainpath /www/nginx/ssl/rj.809022.xyz.cer</code></pre><p>8、重新配置 Nginx</p><pre><code>server {
        listen      443 ssl http2;
        server_name  rj.809022.xyz;

           ssl on;
        ssl_certificate      /www/nginx/ssl/rj.809022.xyz.cer;    # 证书路径
        ssl_certificate_key  /www/nginx/ssl/rj.809022.xyz.key;    # 证书路径
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        root /www/wwwroot/rj.809022.xyz;
        index index.html index.htm;
        location / {
                try_files $uri $uri/ =404;
        }
}

# 强制 http 跳转 https
server {
        listen      80;
        server_name rj.809022.xyz;
        return      301 https://$server_name$request_uri;
}</code></pre><p>9、重启 Nginx<br>我因为安装了宝塔，所以上面的一些建立目录、复制、包括现在重启服务，都是在宝塔下鼠标点击操作<br>之后重启打开自己的网站就会发现上锁了</p><p>10、附加一些命令<br>手动更新证书</p><pre><code>acme.sh --renew -d 这里填写你的域名 --force</code></pre><p>证书列表</p><pre><code>acme.sh --list</code></pre><p>停止更新</p><pre><code>acme.sh --remove -d 要停止服务的域名</code></pre>
]]></content:encoded>
<slash:comments>2</slash:comments>
<comments>https://www.941741.xyz/archives/8.html#comments</comments>
<wfw:commentRss>https://www.941741.xyz/feed/tag/%E8%AF%81%E4%B9%A6/archives/8.html</wfw:commentRss>
</item>
</channel>
</rss>