配置多域名的SSL证书分两种方式,一种是手动生成多域名SAN证书,配置服务器;另一种是使用自动化工具如Certbot来管理多域名证书,尤其是使用Let's Encrypt的免费证书。下面我写一下具体步骤:
1. 生成包含多域名的证书请求(CSR)
创建OpenSSL配置文件(如 openssl.cnf):
ini
复制
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn
req_extensions = req_ext
[ dn ]
CN = example.com 主域名
O = Your Organization
C = Country
[ req_ext ]
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = example.com 主域名
DNS.2 = example.net 其他域名
DNS.3 = sub.example.org 子域名
生成私钥和CSR:
bash
复制
openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr -config openssl.cnf
2. 申请多域名SSL证书
将生成的 server.csr 提交给证书颁发机构(CA),选择支持多域名的证书类型(如多域名证书或SAN证书)。CA签发的证书将包含所有指定的域名。
3. 配置Web服务器
Nginx 示例:
nginx
复制
共享同一证书的多个域名
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/certs/multidomain.crt;
ssl_certificate_key /etc/ssl/private/server.key;
其他配置...
}
server {
listen 443 ssl;
server_name example.net;
ssl_certificate /etc/ssl/certs/multidomain.crt;
ssl_certificate_key /etc/ssl/private/server.key;
其他配置...
}
Apache 示例:
apache
复制
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/multidomain.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
其他配置...
</VirtualHost>
<VirtualHost *:443>
ServerName example.net
SSLEngine on
SSLCertificateFile /etc/ssl/certs/multidomain.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
其他配置...
</VirtualHost>
4. 使用自动化工具(推荐Let's Encrypt)
通过Certbot快速获取多域名证书:
bash
复制
sudo certbot certonly --nginx -d example.com -d example.net -d sub.example.org
或Apache:
bash
复制
sudo certbot certonly --apache -d example.com -d example.net -d sub.example.org
证书会自动配置并包含所有域名,续期也由Certbot自动处理。
关键注意事项:
SNI支持:确保客户端支持SNI(现代浏览器均支持),以便同一IP托管多个证书。
证书类型:确认证书类型为多域名(SAN)或通配符(仅限子域名)。
重新申请:新增域名需重新生成CSR并更新证书。
上面四个个步骤,就可高效配置多域名的SSL证书,以保障多个域名的HTTPS访问安全。