free申请https证书
·
目前有多个免+费 SSL 证书提供商,其中 Let's Encrypt 是最主流的选择,支持自动续期且被所有主流浏览器信任。以下是详细申请步骤:
一、使用 Let's Encrypt(推荐)
Let's Encrypt 是由 ISRG 运营的非营利证书颁发机构,通过 Certbot 工具可轻松完成证书申请与配置。
1. 安装 Certbot
根据你的服务器系统选择对应的安装方式:
# Ubuntu/Debian
sudo apt update
sudo apt install certbot python3-certbot-nginx
# CentOS/RHEL
sudo yum install epel-release
sudo yum install certbot python3-certbot-nginx
# macOS (Homebrew)
brew install certbot
2. 申请证书(以 Nginx 为例)
Certbot 支持自动配置 Nginx,只需运行:
sudo certbot --nginx -d your-domain.com -d www.your-domain.com
参数说明:
--nginx:自动配置 Nginx 服务器-d:指定要申请证书的域名(可添加多个)
3. 手动申请证书(自定义配置)
若需手动配置 Nginx,可先获取证书:
sudo certbot certonly --standalone -d your-domain.com -d www.your-domain.com
或者指定目录
certbot certonly --webroot -w /www/wwwroot/html -d your-domain.com -m your-email@test.com --agree-tos
证书文件将保存至:
/etc/letsencrypt/live/your-domain.com/fullchain.pem # 证书文件
/etc/letsencrypt/live/your-domain.com/privkey.pem # 私钥文件
4. 配置 Nginx 使用证书
修改 Nginx 配置文件(通常位于 /etc/nginx/conf.d/your-domain.conf):
nginx
server {
listen 443 ssl;
server_name your-domain.com www.your-domain.com;
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
# 其他 HTTPS 配置...
}
5. 自动续期证书
Let's Encrypt 证书有效期为 90 天,需定期续期:
# 测试续期命令
sudo certbot renew --dry-run
# 续期命令
sudo certbot renew
# 添加 cron 任务自动续期(每月执行一次)
sudo crontab -e
0 0 1 * * certbot renew --quiet && systemctl reload nginx
二、其他免费证书提供商
除 Let's Encrypt 外,还有以下选择:
-
ZeroSSL
- 特点:提供 90 天免费证书,支持手动或 API 申请
- 官网:zerossl.com
-
Cloudflare SSL/TLS
- 特点:结合 CDN 服务提供免费 SSL 保护
- 适用场景:适合静态网站或需要 CDN 加速的网站
-
Google Trust Services
- 特点:通过合作商(如 Namecheap)提供免费证书
- 注意:需绑定域名服务商
三、申请前的准备工作
-
确保域名已正确解析
- 通过
ping your-domain.com确认能访问到服务器 IP
- 通过
-
开放服务器端口
- 确保服务器防火墙开放 80(HTTP)和 443(HTTPS)端口:
bash
# Ubuntu/Debian (ufw) sudo ufw allow 80 sudo ufw allow 443 # CentOS (firewalld) sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload -
确认 Nginx 配置正确
- 确保域名已正确配置到 Nginx 服务器块中
四、常见问题与解决方案
-
证书申请失败:域名验证不通过
- 检查域名 DNS 解析是否正确
- 确保服务器能通过公网访问
-
Nginx 无法启动
- 检查证书路径是否正确
- 运行
nginx -t验证配置语法
-
证书即将过期
- 手动执行
certbot renew强制更新 - 检查 cron 任务是否正常工作
- 手动执行
通过以上步骤,你可以免费获取并配置 SSL 证书,为网站启用 HTTPS 加密。建议优先选择 Let's Encrypt + Certbot 方案,因其自动化程度高且被广泛支持。
更多推荐
所有评论(0)