Warning: Undefined array key "cperpage" in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 230

Warning: Undefined variable $output in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 300

Warning: Undefined variable $fixed_tags in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 301

Warning: Undefined variable $isshowdots in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 302

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 305

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 308

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 311

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320

Warning: Undefined variable $more_text_link in /www/wwwroot/www.now163.com/wp-content/themes/typology/functions.php on line 320
RHEL5系统apache2启用ssl加密传输 – 理想社会

RHEL5系统apache2启用ssl加密传输

R
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(源码版本):
[url]http://httpd.apache.org/download.cgi[/url]
[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所需的证书
在 httpd-ssl.conf 配置文件里,写着证书、Key文件的默认存放位置为:
SSLCertificateFile “/usr/local/apache2/conf/server.crt”
SSLCertificateKeyFile “/usr/local/apache2/conf/server.key”
所以我们最好来到 apache2/conf 目录下工作:
# cd /usr/local/apache2/conf
A.创建Key文件:
[root@pps conf]# openssl genrsa -des3 -out server.key 1024
执行完后应该在当前目录中有一个server.key文件
B.查看创建的key文件:(不是必须)
# openssl rsa -noout -text -in server.key
C.创建pem文件:(不是必须)
# openssl rsa -in server.key -out server.key.unsecure
D.创建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里输入[url]https://ip[/url]
我用的是IE7,显示“此网站的安全证书有问题”,不用理会它,点击继续显示网页即可。
apache2启用ssl后的默认DocumentRoot “/usr/local/apache2/htdocs/”
可以在 apache2/conf/extra/httpd-ssl.conf 里修改为自己想要的目录。
==================================================
希望只有认证的用户才能访问的话,请继续下面的配置
==================================================
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 1024
B.创建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 -in client.csr -out client.crt -signkey myCA.key -CA myCA.crt -CAkey myCA.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.pfx
F.修改 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”就是要输入的“私钥”密码。
哈哈,利用自己授权的证书访问自己的服务器,感觉有点酷哦~

About the author

Add comment

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

By now163

Your sidebar area is currently empty. Hurry up and add some widgets.