超级简单acme证书申请,不用dns配置,自动续期,个人网站首选

安装条件:

curl https://get.acme.sh | sh
alias acme.sh=~/.acme.sh/acme.sh

准备:

(1)将域名的解析指向服务器,并且服务器开启80端口的http服务

(2)准备acme需要目录

./nginx/html/.well-known/acme-challenge

1 指定初始化

方式一:通过指定dns

acme.sh --issue --server letsencrypt --dns dns_dp -d huisiban.com www.huisiban.com  --webroot /usr/local/nginx/html

方式二:通过自定webroot,(推荐)

acme.sh --issue --server letsencrypt  -d huisiban.com -d www.huisiban.com --webroot /usr/local/nginx/html

2 安装

执行下面的命令会生成证书文件相关的key和pem,改为你自己的路径和文件名

acme.sh --install-cert -d huisiban.com -d www.huisiban.com  --key-file /usr/local/nginx/certs/www.huisiban.com.key --fullchain-file /usr/local/nginx/certs/www.huisiban.com.pem

重要:acme.sh默认开启证书自动更新,acme官方默认60天左右,保证支持crontab

检查系统是否支持crontab ,通过crontab可以查看当前的证书定时任务,下面是我服务器上的

[root@VM-16-2-opencloudos ~]# crontab  -l
*/5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &'
51 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/nul

3 自动更新

这条命令acme自身自动更新

acme.sh --upgrade --auto-upgrade

4 证书申请完成后,就可以配置https 443 服务了

比如我的网站汇思班

server {
    listen 80;
    server_name huisiban.com www.huisiban.com;
    rewrite ^(.*)$ https://www.huisiban.com$1 permanent;
}
server {
    listen       443 ssl;
    server_name  huisiban.com www.huisiban.com;

    ssl_certificate      /usr/local/nginx/certs/www.huisiban.com.pem;
    ssl_certificate_key  /usr/local/nginx/certs/www.huisiban.com.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;


    client_max_body_size 20m;
    client_body_buffer_size 128k;

    gzip on;
    gzip_buffers 32 4K;
    gzip_comp_level 6;
    gzip_min_length 100;
    gzip_types application/javascript text/css text/xml application/font-woff;
    gzip_disable "MSIE [1-6]\.";

    if ( $host = 'huisiban.com') {
        rewrite ^/(.*)$ https://www.huisiban.com/$1 permanent;
    }
    location ^~ /.well-known/acme-challenge/ {
        default_type "text/plain";
        root /usr/local/nginx/html;
    }
    location ~ ^/upload/(.*)\.(png|jpg|jpeg|gif)$ {
        root /opt/img;
        expires 5d;
        set $img_width -;
        set $img_height -;
        # 获取参数size的值
        if ($arg_size ~* "^(\d+)x(\d+)$") {
          set $img_width $1;
          set $img_height $2;
        }
        # 裁剪图片并且调整大小
        image_filter resize $img_width $img_height;

        image_filter_jpeg_quality 25;
        image_filter_buffer 10M;
    }
    location ~ ^/upload/(.*)\.(ico|webp)$ {
        root /opt/img;
    }
    location /fastcms.html {
        alias   /usr/local/nginx/html;
        # 此处的 @router 实际上是引用下面的转发,否则在 Vue 路由刷新时可能会抛出 404
        try_files $uri $uri/ @router;
        # 请求指向的首页
        index  index.html index.htm;
    }
    location /fastcms {
            alias   /usr/local/nginx/html;
    }
    location /fastcms/api {
        proxy_pass http://127.0.0.1:8085;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location / {
        proxy_pass http://127.0.0.1:8085;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;

    }

    # 由于路由的资源不一定是真实的路径,无法找到具体文件
    # 所以需要将请求重写到 index.html 中,然后交给真正的 Vue 路由处理请求资源
    location @router {
      rewrite ^.*$ /index.html last;
    }

}

 参考文章:acme证书申请 - 汇思班 (huisiban.com) 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

流光影下

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值