acme.sh自动申请https证书

本文涉及的产品
实时数仓Hologres,5000CU*H 100GB 3个月
智能开放搜索 OpenSearch行业算法版,1GB 20LCU 1个月
实时计算 Flink 版,5000CU*H 3个月
简介: 该文介绍了如何在Ubuntu 20.04系统上使用acme.sh获取和安装免费的HTTPS证书,适用于已经安装了nginx的环境。首先通过`sudo curl https://get.acme.sh | sh -s email=example@mail.com`安装acme.sh,然后使用`acme.sh --issue -d example.com -w /home/onestudy`生成证书,并用`acme.sh --install-cert`安装到nginx。设置定时任务以定期更新证书,并提供了不同方式的证书获取命令及删除和刷新证书有效性的方法。需确保已配置好域名解析和nginx配置。

本文介绍,使用acmesh自动获取https证书的方法

背景

很多网站都需要https证书,但是很多网站的证书都是收费的,同时也有一些是短期免费的,acme.sh 就提供了一些方法来获取免费的证书 ,并通过设置系统定时任务来获取长期免费。

环境说明

linux Ubuntu 20.04 系统测试 , 且系统已经安装 nginx , nginx version: nginx/1.18.0 (Ubuntu)

查看nginx版本命令 nginx -v

参考官网地址

acmesh wiki

特别说明

exaple@mail.com 请替换为自己实际可用的邮箱
example.com 请替换成自己的域名
您已经设置好域名和服务器之间的正确解析关系 并 配置好的您的nginx配置文件

安装

sudo curl https://get.acme.sh | sh -s email=exaple@mail.com

验证安装情况

```shell
acme.sh --list

Main_Domain KeyLength SAN_Domains CA Created Renew


>## 设置默认参数
```shell
acme.sh --set-default-ca --server zerossl

或 

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

查看默认参数

acme.sh --info

生成https证书步骤

```shell

此命令可以和自己账户关联起来 , 这里不需要执行

acme.sh --register-account --eab-kid GthwFbAaca9kpSEfg6l2KA \

    --eab-hmac-key LLEE43fpeFO4Hp3HryoOfAo0ZC73Z0-_rqWEPK25dLZCaSzCrQ7Gr_609SotUxEk_Phx7C2bZSQCAVcUrC50uw

生成证书

/home/onestudy 目录必须存在 , 目录下面 放了一个index.html 文件 , 用于验证域名是否可以访问. index.html 文件内容见下面单独说明

acme.sh --issue -d example.com -w /home/onestudy

acme.sh --issue -d example.com -w /home/onestudy --force

安装证书

acme.sh --install-cert -d example.com \
--key-file /etc/nginx/cert/example.com.key \
--fullchain-file /etc/nginx/cert/example.com.pem \
--reloadcmd "sudo systemctl force-reload nginx.service"


## index.html 文件内容

>cat /home/onestudy/index.html 
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>One Study</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }
        header {
            background-color: #333;
            color: #fff;
            padding: 20px;
            text-align: center;
        }
        nav {
            background-color: #666;
            padding: 10px;
            text-align: center;
        }
        nav a {
            color: #fff;
            text-decoration: none;
            padding: 10px;
        }
        nav a:hover {
            background-color: #999;
        }
        section {
            padding: 20px;
        }
        footer {
            background-color: #333;
            color: #fff;
            text-align: center;
            padding: 10px;
            position: fixed;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
    </header>
    <nav>
        <a href="#">Home</a>
        <a href="#">About</a>
        <a href="#">Contact</a>
    </nav>
    <section>
        <h2>About Us</h2>
        <p>This is a simple website created for demo purposes.</p>
    </section>
    <footer>
        &copy; 2024 My Website. All rights reserved.
    </footer>
</body>
</html>

其他可以生成证书的命令 , 但在本次是验证不是那么的顺利

acme.sh --issue -d example.com --nginx
acme.sh --issue -d example.com --dns dns_cf
acme.sh --issue --standalone -d example.com
acme.sh --issue --alpn -d example.com

查看定时任务是否存在, 不存在的自行创建

crontab -l

31 11 * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null

删除证书

acme.sh remove example.com

强制提前刷新证书有效期

"/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" --force

目录
相关文章
|
1月前
|
Linux Docker Windows
Docker配置https证书案例
本文介绍了如何为Docker的Harbor服务配置HTTPS证书,包括安装Docker和Harbor、修改配置文件以使用证书、生成自签名证书、配置证书以及验证配置的步骤。
35 2
Docker配置https证书案例
|
2月前
|
安全 Apache Windows
WAMP——配置HTTPS证书
WAMP——配置HTTPS证书
55 1
WAMP——配置HTTPS证书
|
2月前
|
安全 网络安全 Windows
【Azure App Service】遇见az命令访问HTTPS App Service 时遇见SSL证书问题,暂时跳过证书检查的办法
【Azure App Service】遇见az命令访问HTTPS App Service 时遇见SSL证书问题,暂时跳过证书检查的办法
【Azure App Service】遇见az命令访问HTTPS App Service 时遇见SSL证书问题,暂时跳过证书检查的办法
|
2月前
|
Web App开发
Chrome浏览器导出HTTPS证书
Chrome浏览器导出HTTPS证书
43 0
Chrome浏览器导出HTTPS证书
|
2月前
|
网络协议 安全 网络安全
免费申请 HTTPS 证书的八大方法
免费申请 HTTPS 证书的八大方法
|
3月前
|
安全 Java 网络安全
RestTemplate进行https请求时适配信任证书
RestTemplate进行https请求时适配信任证书
56 3
|
4月前
|
前端开发 小程序 应用服务中间件
在服务器上正确配置域名https证书(ssl)及为什么不推荐使用宝塔申请免费ssl证书
在服务器上正确配置域名https证书(ssl)及为什么不推荐使用宝塔申请免费ssl证书
225 4
|
4月前
|
安全 网络安全 Windows
【Azure App Service】遇见az命令访问HTTPS App Service 时遇见SSL证书问题,暂时跳过证书检查的办法
在访问App Service的KUDU工具或使用`az webapp deploy`时遇到SSL错误:`SSL: CERTIFICATE_VERIFY_FAILED`。解决方法是临时禁用Azure CLI的SSL验证。在PowerShell中,设置`$env:ADAL_PYTHON_SSL_NO_VERIFY`和`$env:AZURE_CLI_DISABLE_CONNECTION_VERIFICATION`为1;在Windows命令提示符中,使用`set AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1`。注意,这可能引入安全风险,应仅在必要时使用。
|
3月前
|
数据安全/隐私保护
https【详解】与http的区别,对称加密,非对称加密,证书,解析流程图
https【详解】与http的区别,对称加密,非对称加密,证书,解析流程图
64 0
|
4月前
|
Web App开发 应用服务中间件 网络安全
HTTPS证书到期更换
HTTPS证书到期更换
805 0
下一篇
无影云桌面