为了安全考虑,我们的站点有时候还是需要https加密的,而一般个人用的话,使用自我签发的自签名证书就足够了,但是用户访问的时候会提示”此网站的安全证书有问题”(就像12306一样_(:з」∠)__),体验极差.所以这篇文章主要介绍了本人申请泛域名ssl证书并把它用到自己的站点上,实现https访问的全过程.

在SSLCertificate购买SSL证书

先访问https://www.sslcertificate.cn/new/按照说明进行操作:

1,购买code和输入需要的泛域名(以*.开头),这个不作赘述.

2,这里详细说明下生成csr的全过程:

1
2
3
4
mkdir /tmp/ssl/ #在tmp目录下新建个ssl文件夹
cd /tmp/ssl/ #进入该文件夹
openssl genrsa -out xxoo.pem 2048 #生成私钥
openssl req -new -key xxoo.pem -out xxoo.csr #用私钥生成csr文件

执行上面的第二条指令后,会几行有需要填写的信息:

1
2
3
4
Country Name (2 letter code) [AU]:CN #CN表示中国
...
Common Name:*.yourdomain.com #这里输入之前提交的需要的泛域名(以*.开头)
...

其余信息随意.然后打开刚才生成好的csr文件:

1
cat xxoo.csr

复制到网页上,等待Loading验证完成.xxoo.pem私钥文件留作后面备用.

3,通过验证后根据提供的信息,在DNS解析商(如DNSPOD)添加一条TXT解析记录,然后返回继续验证,成功后就等待证书颁发成功了.然后进邮箱,把证书和链证书的文本(从BEGIN CERTIFICATE到END CERTIFICATE)分别复制并存为两个不同的文件.把颁发*.泛域名的证书保存为services.crt,把链证书保存为chaincer.crt :

1
2
3
4
vim /tmp/ssl/services.crt
#粘帖证书内容,保存后退出
vim /tmp/ssl/chaincer.crt
#粘帖链证书内容,保存后退出

ssl证书颁发成功
ssl证书颁发成功

为Apache安装SSL

由于本人使用的是CentOS,所以安装软件使用yum指令,其他系统可参考其他安装指令(如Ubuntu使用apt-get).

1,如果没有安装apache需要先安装apache:

1
yum install httpd

具体可以参考博主的另两篇文章在Azure上安装CentOS及LAMP博客迁移全攻略中的apache安装和配置部分.

2,如果apache已经正常运行,则需要安装SSL模块:

1
2
yum install mod_ssl #安装SSL模块
/etc/init.d/httpd restart #重启apache服务

3,安装了SSL模块后,如果没有创建一个默认的SSL证书,apache重启可能会失败,本人就提示了证书不存在.
这时就需要导入证书文件了.

配置泛域名SSL证书

1,我们先在ssl的目录中新建一个文件夹,方便放几个证书文件:

1
2
cd /etc/pki/tls/ #安装完SSL模块后进入该文件夹
mkdir mycert #创建个好记的证书存放文件夹的名称

2,拷贝所需文件:

1
2
3
cp /tmp/ssl/xxoo.pem /etc/pki/tls/mycert/privatekey.key #拷贝私钥文件,存为后缀名为.key的文件
cp /tmp/ssl/services.crt /etc/pki/tls/mycert/services.crt #拷贝证书文件
cp /tmp/ssl/chaincer.crt /etc/pki/tls/mycert/chaincer.crt #拷贝链证书文件

3,进入apache配置文件并修改ssl配置文件:

1
vim /etc/httpd/conf.d/ssl.conf

找到以下类似段落,并修改为如下的路径:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/pki/tls/mycert/server.crt

# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you’ve both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/pki/tls/mycert/privatekey.key

# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
SSLCertificateChainFile /etc/pki/tls/mycert/chaincer.crt

其实总结起来也就是修改以下三行:

1
2
3
SSLCertificateFile /etc/pki/tls/mycert/server.crt #泛证书存放路径
SSLCertificateKeyFile /etc/pki/tls/mycert/privatekey.key #私钥存放路径
SSLCertificateChainFile /etc/pki/tls/mycert/chaincer.crt #链证书存放路径

然后,重启apache服务:

1
service httpd restart

然后在浏览器中访问https://你的网站链接,就可以看到,泛域名SSL证书正常工作了~ ~ !

PS:

SSL安全检查: https://sslcheck.globalsign.com/cn 这个是SSLCertificate官网自带的检测,功能十分强大.根据检测结果进行安全配置吧~

SSL心脏出血漏洞(beast漏洞)修复:
CentOS直接更新openssl即可:

1
yum update openssl

更新完重启相关服务.检测是否修复成功:

1
rpm -q --changelog openssl-1.0.1e | grep CVE-2014-0160

如果出现”- fix CVE-2014-0160 - information disclosure in TLS”表示漏洞已经修复.

其他系统参照这里:CentOS 64位修复openssl漏洞办法 - 漩涡 - PHP,Wordpress优化

SSL状态检查:访问这里测试(如果之前没有使用链证书的话,中级根证书将处于为安装状态.虽然这样https也能工作,但进行SSL状态检查就会发现颁发机构不可信)

证书,链证书和CA:
证书,链证书和CA

参考链接:
Apache SSL安装与配置

sslcertificate帮助说明

如何在SSLCertificate购买SSL证书

泛域名ssl证书搭建全攻略

CentOS 64位修复openssl漏洞办法 - 漩涡 - PHP,Wordpress优化