acme.sh 添加SSL

首先LNMP下的SSL添加有问题 不如直接使用acme.sh反正也是用他的

安装:

curl https://get.acme.sh | sh -s email=your@email.com
#需要设置你的邮箱
source ~/.bashrc

acme.sh -v
#查看安装情况

使用letsencrypt

acme.sh --set-default-ca --server letsencrypt

修改你的nginx的conf

设置:.well-know (lnmp 里面的需要修改) 请注释掉之前的/.well-known/然后插入新的

location ^~ /.well-known/acme-challenge/ {
            allow all;
            default_type text/plain;
            root /home/wwwroot/quant.comic.org.cn;
        }

然后 lnmp nginx restart 实现nginx重启

acme.sh --issue -d abc.cn -w /home/wwwroot/abc.cn

安装好了会显示地址:

[Sun Apr 12 04:54:22 PM CST 2026] Your cert is in: /root/.acme.sh/abc.cn_ecc/abc.cn.cer
[Sun Apr 12 04:54:22 PM CST 2026] Your cert key is in: /root/.acme.sh/abc.cn_ecc/abc.cn.key
[Sun Apr 12 04:54:22 PM CST 2026] The intermediate CA cert is in: /root/.acme.sh/abc.cn_ecc/ca.cer
[Sun Apr 12 04:54:22 PM CST 2026] And the full-chain cert is in: /root/.acme.sh/abc.cn_ecc/fullchain.cer

#其中abc.cn是你的证书文件位置 在root的.acme.sh下面

nginx下创建ssl目录

mkdir /usr/local/nginx/conf/ssl

一键移动证书到NGINX

acme.sh --install-cert -d abc.cn \
--key-file /usr/local/nginx/conf/ssl/abc.cn.key \
--fullchain-file /usr/local/nginx/conf/ssl/abc.cn.crt \
--reloadcmd "nginx -t && service nginx reload"

重新配置conf 在lnmp的域名下配置

server
{
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name abc.cn;

    root  /home/wwwroot/abc.cn/public;
    index index.html index.htm index.php default.html default.htm default.php;

    # SSL 证书位置
    ssl_certificate /usr/local/nginx/conf/ssl/abc.cn.crt;
    ssl_certificate_key /usr/local/nginx/conf/ssl/abc.cn.key;

    include rewrite/thinkphp.conf;
    include enable-php-pathinfo.conf;

    location ~ .*\.(gif|jpg|jpeg,png,bmp,swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js,css)?$
    {
        expires      12h;
    }

    location ~ /\.
    {
        deny all;
    }

    access_log  /home/wwwlogs/abc.cn.log;
}

配置443端口

ufw allow 443

查看443 端口

netstat -lntp | grep 443

腾讯云 阿里云的话可能要在云服务器配置中打开443 端口

此条目发表在None分类目录。将固定链接加入收藏夹。

发表回复