本次坏境:CA和apache为同一台主机
先使本机作为CA服务端:
[[email protected]~]#yum -y install openssl openssl-devel
[[email protected]~]#vi /etc/pki/tls/openssl.cnf
[ CA_default ]
dir = ../../CA
改为:
[ CA_default ]
dir= /etc/pki/CA
为了减少不必要的重复操作,可以预先定义[ req_distinguished_name ]下面的一些内容,自定义即可,具体的就不多说了
:wq
[[email protected]~]#cd /etc/pki/CA
[[email protected] CA]# mkdir certs newcerts crl
[[email protected] CA]# touch index.txt
[[email protected] CA]# echo 00 > serial
[[email protected] CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048) ##生成自签密钥
[[email protected] CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3657 ##生成自签证书
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [BJ]:
Locality Name (eg, city) [HaiDian]:
Organization Name (eg, company) [TEXT]:
Organizational Unit Name (eg, section) [DEV]:
Common Name (eg, your name or your server‘s hostname) []:ca.text.com
Email Address []:[email protected]
由于openssl.cnf里面定义了部分内容,上面一直敲回车,直到Common Name (eg, your name or your server‘s hostname) []: (此为CA服务名称,可自定义)
最后一个邮箱也可自定义
都敲完后,我们的CA服务端就完成了,继续往下做
Apache动态编译安装:
[[email protected] CA]# tar -xf httpd-2.2.9.tar -C /usr/local/src/
[[email protected] CA]#cd /usr/local/src/httpd-2.2.9/
[[email protected] httpd-2.2.9]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-z=/usr/local/zlib/ --with-included-apr --enable-so --enable-mods-shared=most
[[email protected] httpd-2.2.9]#make;make install
Apache配置ssl:
[[email protected] CA]# rpm -qa |grep mod_ssl
[[email protected] CA]# yum -y install mod_ssl ##如没有mod_ssl直接使用yum安装即可
[[email protected] CA]# rpm -ql mod_ssl ##查看mod_ssl生成的配置文件位置
[[email protected] CA]# cd /etc/httpd
[[email protected] httpd]# mkdir ssl
[[email protected] httpd]# cd ssl
[[email protected] ssl]# (umask 077; openssl genrsa -out httpd.key 2048) ##生成密钥
[[email protected] ssl]#openssl req -new -key httpd.key -out httpd.csr ##生成证书签署请求
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [BJ]:
Locality Name (eg, city) [HaiDian]:
Organization Name (eg, company) [TEXT]:
Organizational Unit Name (eg, section) [DEV]:
## 上面五条一定要和CA服务器设置一致,本次实验都是在一台主机上,所以直接敲回车即可
Common Name (eg, your name or your server‘s hostname) []:text.bj.com ##一定要是客户端访问的地址,而不是上面CA设置的地址
Email Address []:[email protected] ##自定义
[[email protected] ssl]#openssl ca -in httpd.csr -out httpd.crt -days 3657 ## ca签署命令,敲两次y和回车即可(由于都在一台机器上,直接签署就可以了,如果在不同机器上,把http的证书签署请求文件拷贝到CA服务端签署后拷贝回来就可以了)
[[email protected] ssl]#vi /etc/httpd/conf.d/ssl.conf
默认443端口不变
查看下面两句是否存在,不存在加上
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
<VirtualHost _ default_443>
改为:
<VirtualHost 192.168.1.99:443> ##web服务器或web虚拟主机IP地址
添加下面两句
ServerName text.bj.com ##上面定义的地址
DocumentRoot "/var/www/html" ##网站目录位置,如设置的虚拟主机,此位置需和apache配置文件里虚拟主机定义的位置一致
SSLEngine on ##确保开启
SSLCertificateFile /etc/httpd/ssl/httpd.crt ## 证书存放位置
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key ##密钥存放位置
:wq
[[email protected] ssl]#echo text.bj.com > /var/www/html/index.html
[[email protected] ssl]#/etc/init.d/httpd start
[[email protected] ssl]#netstat –tnlp ##查看443端口是否开启
访问https://text.bj.com
提示“该网站的安全证书不受信任”
解决:
拷贝/etc/pki/CA/cacert.pem到客户端上安装即可(winPC后缀改为.crt后双击安装)
Apache配置SSL 实现https访问,布布扣,bubuko.com