您的位置:首页 > 运维架构 > Apache

RHEL5系统apache2启用ssl加密传输

2009-03-26 21:16 387 查看
1、安装包
Linux下要启用SSL,得有openssl包,以下是我RHEL5系统rpm安装的openssl:
[root@pps software]# rpm -qa | grep ssl
openssl-0.9.8b-8.3.el5
openssl-devel-0.9.8b-8.3.el5下载最新版本的apache2(源码版本):
http://httpd.apache.org/download.cgi[root@pps software]# tar zxf httpd-2.2.11.tar.gz
[root@pps httpd-2.2.11]# ./configure --enable-so --enable-ssl
【注意】如果是编译安装的openssl,需要在再加 --with-ssl=/usr/local/openssl 选项
[root@pps httpd-2.2.11]# make
[root@pps httpd-2.2.11]# make install默认情况下apache2安装在 /usr/local/apache2修改 apache2/conf/httpd.conf 文件,在文件中找到下面一行,把注释去掉:
Include conf/extra/httpd-ssl.conf 2、创建apache2启用SSL所需的证书参考文章:
http://www.blogjava.net/jjwwhmm/archive/2008/04/25/195964.html在 httpd-ssl.conf 配置文件里,写着证书、Key文件的默认存放位置为:
SSLCertificateFile "/usr/local/apache2/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"所以我们最好来到 apache2/conf 目录下工作:
# cd /usr/local/apache2/confA.创建Key文件:
[root@pps conf]# openssl genrsa -des3 -out server.key 1024
执行完后应该在当前目录中有一个server.key文件B.查看创建的key文件:(不是必须)
# openssl rsa -noout -text -in server.keyC.创建pem文件:(不是必须)
# openssl rsa -in server.key -out server.key.unsecureD.创建scr文件:
[root@pps conf]# openssl req -new -key server.key -out server.csr
执行完后应该在当前目录中有一个server.csr文件E.创建crt文件:
[root@pps conf]# openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt执行完后应该在当前目录中有一个server.crt文件【注意】如果是由源码编译安装的openssl需要加上openssl的路径,如:
/usr/local/openssl/bin/openssl 3、启动apache2
[root@pps conf]# apachectl -k start
Apache/2.2.11 mod_ssl/2.2.11 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.Server pps.hoho.com:443 (RSA)
Enter pass phrase:OK: Pass Phrase Dialog successful.如果输入的Key密码不对,那么apache2将不能启动。 4、在IE里输入https://ip
我用的是IE7,显示“此网站的安全证书有问题”,不用理会它,点击继续显示网页即可。 apache2启用ssl后的默认DocumentRoot "/usr/local/apache2/htdocs/"
可以在 apache2/conf/extra/httpd-ssl.conf 里修改为自己想要的目录。 ==================================================
希望只有认证的用户才能访问的话,请继续下面的配置
================================================== 参考文章:
http://www.chinaunix.net/jh/13/469276.html 5、创建认证客户所需要的CA证书CA(Certificate Authority)是数字证书认证中心的简称,是指发放、管理、废除数字证书的机构。CA的作用是检查证书持有者身份的合法性,并签发证书(在证书上签字),以防证书被伪造或篡改,以及对证书和密钥进行管理。 我建一个ssl.crt目录来工作:
# mkdir -p /usr/local/apache2/conf/ssl.crt/
# cd /usr/local/apache2/conf/ssl.crt/A.创建CA的key文件:
[root@pps ssl.crt]# openssl genrsa -des3 -out myCA.key 1024B.创建CA的crt文件:
[root@pps ssl.crt]# openssl req -new -x509 -days 3650 -key myCA.key -out myCA.crt【现在我有了这个myca.crt, 这个CERT相当与一个图章,用这个图章盖过的请求才可以访问我的apache2-https服务器】C.用户请求生成一个csr文件:
[root@pps ssl.crt]# openssl req -new -out client.csr【这里可以用普通用户权限来生成一个请求CSR文件,这里为了方便我就用root用户申请生成一个。用“图章”盖过印的CSR请求产生的一个cert才有效。】D.生成用户可以使用的crt证书文件:
[root@pps ssl.crt]# openssl x509 -req -inclient.csr -out client.crt -signkey myCA.key -CA myCA.crt -CAkeymyCA.key -CAcreateserial -days 3650【执行完生成了一个client.crt文件. 也就是一个盖过章的certificate】
这个certificate是BASE64形式的,要转成PKCS12才能装到IE,/NETSCAPE上E.导出为pfx证书:
[root@pps ssl.crt]# openssl pkcs12 -export -in client.crt -inkey myCA.key -out client.pfxF.修改 httpd-ssl.conf 配置文件:
在 httpd-ssl.conf 文件中找到 SSLCACertificateFile 的配置,把注释去掉并修改其路径值为文件路径为client.crt,我的如下:
SSLCACertificateFile "/usr/local/apache2/conf/ssl.crt/myCA.crt"
把以下两行注释去掉:
SSLVerifyClient require
SSLVerifyDepth 10重新启动apache2,当再次访问apache2的时候,IE就会弹出窗口选择证书了。
将 client.pfx 从RHEL5取回Windows,在IE弹出串口选择证书的时候选择它即可。pfx 即 Personal Information Exchange 个人信息交换 ==========================================
IE7证书导入(本人电脑没有IE6可试)
========================================== Internet选项 --> 内容 --> 证书 --> 个人 --> 导入 --> 选择client.pfx提示输入“私钥”密码的时候,输入在创建client.pfx文件时所键入的 Export Password:
[root@pps ssl.crt]# openssl pkcs12 -export -in client.crt -inkey myCA.key -out client.pfx
Enter pass phrase for myCA.key: zhaozh
Enter Export Password: hoho
Verifying - Enter Export Password: hoho上面的例子,"hoho"就是要输入的“私钥”密码。哈哈,利用自己授权的证书访问自己的服务器,感觉有点酷哦~ ------------------------------------------------------------------------------------------赵小蜗牛QQ: 755721501E-mail: [email]snailwarrior@qq.com[/email]在不断奉献中谋求生存发展、打造自己的优秀人品,用人性最本质最动人的一面“营销”自己! 本文出自 “小蜗牛技术之家” 博客,请务必保留此出处http://snailwarrior.blog.51cto.com/680306/137657
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  职场 休闲