环境为 Centos7.2,其他环境可能略有不同。

vi 编辑 httpd/conf.d/ssl.conf 文件,我的目录是 /etc/httpd/conf.d

查找

Listen 443 https

NameVirtualHost *:443

是否存在,如果没有则添加,如果有则把前面的 # 号去掉。

1. 单网站配置 SSL 证书

假设下载证书的公共key为 public.pem,私key为 80note.key,chain key为 chain.pem 先将它们上传到服务器目录中,这里我传到 /home/cert 目录中做示例。 在 ssl.conf 中添加如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<VirtualHost *:443>
DocumentRoot "/home/web/80note"
ServerName 80note.com
SSLEngine on
SSLCertificateFile /home/cert/public.pem
SSLCertificateKeyFile /home/cert/80note.key
SSLCertificateChainFile /home/cert/chain.pem
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/web/80note"
ServerName www.80note.com
SSLEngine on
SSLCertificateFile /home/cert/public.pem
SSLCertificateKeyFile /home/cert/80note.key
SSLCertificateChainFile /home/cert/chain.pem
</VirtualHost>

其中:

  • /home/web/80notewww.80note.com 网站文件目录

  • 80note.com 是该网站域名

  • /home/cert/public.pem 是公共 key 的文件位置。

  • /home/cert/80note.key 是私 key 的文件位置。

  • /home/cert/chain.pem 是 chain key 的文件位置。

这里做了两个配置,分别适配 80note.com 和 www.80note.com 域名。

2. 多网站配置 SSL 证书

假设另一个网站证书的公共key为public.crt,私key为zuihuimai.key,chain key为chain.pem将它们上传到服务器另一个目录中,这里我传到/home/cert1目录中做示例

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
<VirtualHost *:443>
DocumentRoot "/home/web/80note"
ServerName 80note.com
SSLEngine on
SSLCertificateFile /home/cert/public.pem
SSLCertificateKeyFile /home/cert/80note.key
SSLCertificateChainFile /home/cert/chain.pem
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/web/80note"
ServerName www.80note.com
SSLEngine on
SSLCertificateFile /home/cert/public.pem
SSLCertificateKeyFile /home/cert/80note.key
SSLCertificateChainFile /home/cert/chain.pem
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/web/zuihuimai"
ServerName zuihuimai.net
SSLEngine on
SSLCertificateFile /home/cert1/public.crt
SSLCertificateKeyFile /home/cert1/zuihuimai.key
SSLCertificateChainFile /home/cert1/chain.crt
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/web/zuihuimai"
ServerName www.zuihuimai.net
SSLEngine on
SSLCertificateFile /home/cert1/public.crt
SSLCertificateKeyFile /home/cert1/zuihuimai.key
SSLCertificateChainFile /home/cert1/chain.crt
</VirtualHost>

配置完成保存后,需要重启 apache 服务。

1
service httpd restart