大体步骤
1,安装apache2,安装mod_ssl模块,并让httpd加载。此模块是让httpd支持ssl。
3,提供https使用的密钥文件。
4,测试
===========================================================================================
#yum -y install httpd 安装httpd程序
#yum -y install mod_ssl 安装mod_ssl模块
#rpm -ql mod_ssl 查看mod_ssl包都生成了那些文件
/etc/httpd/conf.d/ssl.conf 生成了作为httpd主配置文件的ssl配置文件
/usr/lib64/httpd/modules/mod_ssl.so httpd支持ssl使用的库文件
/var/cache/mod_ssl https会话中的缓存文件,缓存加密用到的算法,使用的公钥等信息。
=======================================================================================
/etc/httpd/conf.d/ssl.conf 文件主要的配置功能解释
-------------------------------------------------
LoadModule ssl_module modules/mod_ssl.so 设置加载的ssl模块
Listen 443 设定httpd使用https时监听的端口
SSLPassPhraseDialog builtin 设置建立ssl会话时使用的协商机制 ,builtin为内建机制
SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000) 会话缓存的目录
SSLSessionCacheTimeout 300 会话缓存超时时间
ErrorLog logs/ssl_error_log 错误专用日志
TransferLog logs/ssl_access_log 会话过程日志
LogLevel warn 错误日志记录的级别
SSLEngine {on|off} 是否开启ssl功能
SSLProtocol all -SSLv2 使用的ssl协议版本,all表示使用所有版本,-SSLv2表示明确不使用sslv2版本。这里表示只使用sslv3和tlsv1版本协议
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW 双方使用的加密算法,!表示不使用此种加密算法
SSLCertificateFile /etc/pki/tls/certs/localhost.crt 服务器没的证书文件
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key 服务器端的私钥文件
DocumentRoot "/var/www/html" 指定要为那个站点使用ssl。每个ip只能为一个虚拟主机使用ssl。
ServerName www.wukui.net.cn 指定为那个主机使用ssl。一般站点使用http和https的时候都是把需要使用https和http访问的内容分开的。访问不同的内容使用不同的协议。
=========================================================================================
为https服务签发证书。一般生产环境为了让客户端请求时,能够识别证书是由pki官方所发,这时需要申请证书。这里是实验环境,自己给自己发证。
1,为ca生成密钥。
[root@wukui ~]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048) Generating RSA private key, 2048 bit long modulus ...............+++ ........................+++ e is 65537 (0x10001)
2,CA为自己签发证书。
[root@wukui CA]# cd /etc/pki/CA [root@wukui CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 10000
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) [XX]:CN 指定国家代码等等
State or Province Name (full name) []:NMG
Locality Name (eg, city) [Default City]:XL
Organization Name (eg, company) [Default Company Ltd]:wukui
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:caserver.wukui.net.cn
Email Address []:
[root@wukui CA]# ll 查看自签的证书,index.txt是证书索引,serial是证书序例号刚开始创建要手动写序例号从多少开始,这两个文件一定要有。 total 24 -rw-r--r-- 1 root root 1318 Aug 8 20:27 cacert.pem drwxr-xr-x. 2 root root 4096 Jun 5 20:58 certs drwxr-xr-x. 2 root root 4096 Jun 5 20:58 crl -rw-r--r-- 1 root root 0 Aug 2 12:57 index.txt drwxr-xr-x. 2 root root 4096 Jun 5 20:58 newcerts drwx------. 2 root root 4096 Aug 8 20:22 private -rw-r--r-- 1 root root 3 Aug 2 12:57 serial
[root@wukui CA]# mkdir /etc/httpd/ssl 创建一个目录, 为https保存密钥文件的目录 [root@wukui CA]# cd /etc/httpd/ssl [root@wukui ssl]# (umask 077; openssl genrsa -out httpd.key 1023) 为自己生成密钥
[root@wukui 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) [XX]:CN
State or Province Name (full name) []:NMG
Locality Name (eg, city) [Default City]:XL
Organization Name (eg, company) [Default Company Ltd]:wukui
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www.wukui.net.cn 一定要写客户端请求时的fqdn名
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@wukui ssl]# openssl ca -in httpd.csr -out httpd.crt -days 1000 为自己签发证书
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Aug 8 12:39:28 2014 GMT
Not After : May 4 12:39:28 2017 GMT
Subject:
countryName = CN
stateOrProvinceName = NMG
organizationName = wukui
organizationalUnitName = ops
commonName = www.wukui.net.cn
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
BF:3B:9E:6A:AF:17:B7:CB:5F:D5:0A:4F:E0:F8:4B:91:AE:E1:2E:3D
X509v3 Authority Key Identifier:
keyid:00:60:C4:D1:C9:85:D5:01:A5:69:F1:B3:7D:E0:EB:D6:9F:87:85:62
Certificate is to be certified until May 4 12:39:28 2017 GMT (1000 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
---修改配置文件---------------------------------------------------------------------------
主要修改ssl.conf以下两项
SSLCertificateFile /etc/httpd/ssl/httpd.crt 指定证书文件的位置
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key 指定私钥文件的位置
修改主配置文件以下选项定义的主机名,这里的主机名一定要我证书签发时的实体名一样,否则无效。
ServerName www.wukui.net.cn
# service httpd restart 重启httpd服务,修改端口只有重启服务才可以生效。reload不可以。
-----在windwos下测试------------------------------------------------------
使用https协议测试,由于没有把证书导入到系统中,所以会有以下提示。
把自己签名过的证书导入的windows中。证书文件在linux主机上的/etc/pki/CA/cacert.pem 。到windows上需要把后缀名改为.crt。上面签发证书的时候指定的位置。安装步骤如下:
再次中IE中打开就不会提示证书不受信息了。 但在firefox和chrome浏览器还会提示。
修改firefox不提示证书不受信息的方法,在浏览器地址栏里输入 about:config,把红框里的选项改为与下图一样,重启即可。
转载于:https://blog.51cto.com/wukui/1538314