avatar

sunday

Sunday's Blog

  • 首页
主页 使用acme.sh和cloudflare托管的域名生成网站的ssl通配符证书
文章

使用acme.sh和cloudflare托管的域名生成网站的ssl通配符证书

发表于 2023-12-18 更新于 2023-12- 18
作者 sunday 已删除用户
9~11 分钟 阅读

1.安装acme.sh

在root目录

curl https://get.acme.sh | sh -s email=my@example.com

2.使用cloudflare的api密钥在服务器上生成环境变量CF_Key和CF_Email

①先去cloudflare(点击这里)官网获取api密钥

获取后在服务器执行,请把CF_Key 和CF_Email 换成自己的

export CF_Key="763eac4f1bcebd8b5c95e9fc50d010b4"
export CF_Email="alice@example.com"

3.生成网站的通配符证书

./.acme.sh/acme.sh --issue --dns dns_cf -d example.com -d '*.example.com'

如果遇到下图这种情况,说明ZeroSSL服务商抽风了,可在命令后面加--server letsencrypt ,没遇到的话可跳到第4点

./.acme.sh/acme.sh --issue --dns dns_cf -d example.com -d '*.example.com' --server letsencrypt

或者设置默认的ca证书服务商为letsencrypt

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

4.配置证书

生成的证书地址在/root/.acme.sh/<你的域名名称>/ ,如图

在nginx 里配置证书

server {
  # 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验
  listen 443 ssl http2;
  server_name <你的域名名称>;

  # 证书的公私钥
  ssl_certificate /root/.acme.sh/<你的域名名称_ecc>/fullchain.cer;
  ssl_certificate_key /root/.acme.sh/<你的域名名称_ecc>/<你的域名名称>.key;

    # gzip config
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";

  location / {
        # 用于配合 browserHistory使用
        try_files $uri $uri/index.html /index.html;

  }
  location /api {
      proxy_pass <你的域名名称,如: https://example.com>;
      proxy_set_header   X-Forwarded-Proto $scheme;
      proxy_set_header   Host              $http_host;
      proxy_set_header   X-Real-IP         $remote_addr;
  }
}

配置好之后,不要忘记执行nginx -s reload重新读取nginx配置

软件安装
软件安装
许可协议:  CC BY 4.0
分享

相关文章

8月 30, 2025

Cursor IDE中开发IOS应用——支持热更新

1.需要安装的软件 sweetpad Inject 或者 HotSwiftUI I

7月 30, 2025

申请Google oauth授权验证,并通过验证中心

1.申请一个google project https://console.cloud.google.com/projectcreate?previousPage 到这个页面申请一个项目,进入项目 然后点击左上角选择进入oauth 权限请求页面

7月 29, 2025

Coze Studio 一键安装工具,马上开始你的AI工作流

1.clone项目,一键安装 git clone https://github.com/hst-Sunday/oneclick-coze.git cd oneclick-coze chmod +x coze-studio.sh ./coze-studio.sh 这个安装命令也支持windows11的

下一篇

ubuntu系统安装最新的nginx版本

上一篇

国内一键安装docker/compose并替换国内dockerHub镜像源

最近更新

  • ios18 swiftUI 开发的一些问题
  • Cursor IDE中开发IOS应用——支持热更新
  • nginx + acme 不占用80端口申请证书
  • 免费CDN 阿里云ESA 加速国内网站
  • nextjs15使用ai sdk的一些问题

热门标签

nginx acme 强制跳转HTTPS nodejs 代理 mac 神器 vue3 工具 docker

目录

©2025 sunday. 保留部分权利。

使用 Halo 主题 Chirpy