免费证书申请

SSL 证书可以让你的网站支持 HTTPS,提升安全性和可信度。以下介绍几种常见的免费 SSL 证书申请方式。

1. 使用 caddy 自动代理并生成 SSL

Caddy 是一个自动化 HTTPS 的 Web 服务器,支持自动申请和续签 Let’s Encrypt 证书。

Caddy 配置示例

1
2
3
4
example.com {
reverse_proxy 127.0.0.1:8080
encode gzip
}

Caddy 会自动为域名申请并续签 SSL 证书,无需手动操作。


2. 使用 nginx 配置 IP 证书

以 IP 证书 nginx 配置为例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
add_header "Access-Control-Allow-Origin" "*";
root /home/www;
index index.html index.htm test.html demo.html;
}
return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
# listen [::]:443 ssl http2;

ssl_certificate /etc/nginx/conf.d/182.61.6.105.crt;
ssl_certificate_key /etc/nginx/conf.d/182.61.6.105.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m; # about 40000 sessions
ssl_session_tickets off;

# curl https://certbase.com/ffdhe2048.txt > /path/to/dhparam
# ssl_dhparam /path/to/dhparam;
# intermediate configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;

# HSTS (ngx_http_headers_module is required) (63072000 seconds)
# add_header Strict-Transport-Security "max-age=63072000" always;

# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;

# verify chain of trust of OCSP response using Root CA and Intermediate certs
# ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;

# replace with the IP address of your resolver
# resolver 127.0.0.1;
location / {
add_header "Access-Control-Allow-Origin" "*";
root /home/www;
index index.html index.htm test.html demo.html;
}
}

3. Let’s Encrypt 免费证书

Let’s Encrypt 是最流行的免费 SSL 证书颁发机构,支持自动化申请和续签。

Certbot 快速申请

1
2
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx

根据提示输入你的域名,自动配置 nginx 并获取证书。


4. Cloudflare 免费 SSL

Cloudflare 提供免费的 Universal SSL,只需将域名接入 Cloudflare 即可自动启用 HTTPS,无需服务器端配置证书。

步骤

  1. 注册 Cloudflare 账号并添加你的域名。
  2. 修改域名 DNS 服务器为 Cloudflare 提供的地址。
  3. 在 Cloudflare 控制台开启 SSL/TLS。

5. 其他免费 SSL 证书平台

这些平台也支持 ACME 协议,可以配合 certbot 或 acme.sh 工具自动化申请。


总结

  • 推荐使用 Caddy 或 Certbot 自动化申请和续签。
  • Cloudflare 适合不方便配置服务器证书的场景。
  • 证书到期前请及时续签,避免服务中断。

如有问题欢迎留言交流。