23
2025
05
14:44:21

如何免费申请SSL证书并无限续期

1. SSL证书的作用

  • 数据加密和传输安全‌:SSL证书通过TLS/SSL协议加密传输,确保数据在传输过程中不会被截获或篡改。这可以有效防止黑客通过钓鱼攻击和中间人攻击获取用户的敏感信息,如支付信息、登录凭证等‌
  • 提升搜索引擎排名‌:部署了HTTPS的网站在搜索引擎中的排名会更高,因为HTTPS协议表明网站采用了加密连接,提升了用户的数据安全感和信任度。这有助于降低用户的跳出率,延长用户在网页上的停留时间‌
  • 增强用户体验‌:浏览器地址栏的“绿色小锁”和“https://”前缀可以让用户感到安全,减少用户因不安全警告而跳出网站的情况。此外,SSL证书可以屏蔽一些无良广告的干扰,减少客户流失
  • 在开发微信小程序时,如果是自己部署后端API,必须使用带有https的域名

2. 安装要求

  1. 一个已备案并配置解析的域名,如鹅云或阿里云申请
  2. 一台公网服务器(linux),如鹅云或阿里云
  3. nginx web服务器

3. 安装步骤

3.1 系统依赖更新

CenterOS系统:


yum update && yum install curl -y && yum install cron -y && yum install socat -y

Debian/Ubuntu系统


apt-get update && apt-get install curl -y && apt-get install cron -y && apt-get install socat -y

3.2 安装acme.sh脚本

3.2.1 使用curl安装

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

3.2.2 使用GIT安装

  1. yum install git

  2. git clone https://github.com/acmesh-official/acme.sh

  3. cd acme.sh ./acme.sh --install -m 1111@qq.com

  4. source ~/.bashrc 重新加载bash

3.3 注册并配置域名密钥(鹅云)

  1. wx扫码就可以登录DNSPod,否则需要注册绑定。登录之后,点击头像下的 「API密钥」: 
    图片
  2. 配置域名密钥到服务器环境变量


export DP_Id='你的ID'
export DP_Key='你的Token'

3.4 申请证书

  1. 使用下面命令,假设域名是:abc.com

acme.sh  --register-account  -m 邮箱@qq.com --server zerossl  //注册账号
acme.sh --issue --dns dns_dp -d kikakika.com -d *.abc.com  //颁发证书

  1. 默认生成的证书都放在安装目录 ~/.acme.sh/ 下,但是请不要直接使用。而是使用 --installcert 命令安装证书,这里默认你已装好nginx

acme.sh  --installcert  -d  aaa.cn   \
        --key-file   /etc/nginx/ssl/aaa.cn.key \
        --fullchain-file /etc/nginx/ssl/fullchain.cer \        
        --reloadcmd  "systemctl reload nginx.service

  1. 上面安装完,acme会自动续期,可以查看定时任务:crontab -l

3.5 配置nginx

这里支持通配符证书,自己去域名管理创建子域名


  • ssl_certificate_key   /etc/nginx/ssl/abc.com.key;
    server {    listen 443 ssl;    server_name   api.abc.com;    location / {        client_max_body_size  10M;             proxy_pass         http://localhost:5268;        proxy_http_version 1.1;        proxy_set_header   Upgrade $http_upgrade;        proxy_set_header   Connection $connection_upgrade;        proxy_set_header   Host $host;        proxy_cache_bypass $http_upgrade;        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header   X-Forwarded-Proto $scheme;    } }
    server {    listen        80;    server_name   api.abc.c;    return 301 https://$host$request_uri;}




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://hqyman.cn/post/11334.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: