rh333 - 利用apache搭建简易https服务器

来源:互联网 发布:mac air 文件夹整理 编辑:程序博客网 时间:2024/05/29 12:17
rh333 - 利用apache搭建简易https服务器


安装httpd以及ssl包
yum install httpd mod_ssl -y


生成web服务器私钥和证书请求文件(csr)
cd /etc/httpd/conf/
openssl genrsa out httpd.key 1024
openssl req -new -key httpd.key -out httpd.csr


使用自建的CA中心签名web服务器公钥
cd /etc/httpd/conf/
openssl ca -in httpd.csr -out httpd.crt
如何搭建CA中心请参考:
rh333 - 搭建简易CA中心
http://blog.csdn.net/t0nsha/article/details/8816288


配置apache启用ssl支持
<VirtualHost 192.168.0.20:443>
DocumentRoot /var/www/html/www20
ServerName www20.example.com
SSLEngine on
SSLCertificateFile /etc/httpd/conf/httpd.crt
SSLCertificateKeyFile /etc/httpd/conf/httpd.key
</VirtualHost>


重起httpd服务并测试
/etc/init.d/httpd restart


查看已签名证书的指纹
openssl x509 -fingerprint -in httpd.crt -noout -sha1
openssl x509 -fingerprint -in httpd.crt -noout -md5


使用openssl验证ssl连接
openssl s_client -connect www20.example.com:443 -CAfile my-ca.crt
...
Verify return code: 0 (ok) #返回这行表示使用了CA签名的证书

使用Firefox倒入ca中心证书,然后访问ssl加密站点https://www20.example.com,
如果能够正常显示index.html内容并且没有其他错误或者提示则表示配置正确。


碰到的一些错误:

1. DocumentRoot改动无效
原因: 如果没有具体化VirtualHost,则会一直使用默认的DocumentRoot(/var/www/html),忽略VirtualHost中的DocumentRoot。
解决方法: 将<VirtualHost *:443> 改为 <VirtualHost 192.168.0.20:443>


2. Firefox安装了CA中心证书后,仍然报证书不可信任(sec_error_unknow_issuer),检查配置信息没有错误.
原因: 可能来自服务段也可来自客户端:Apache服务器端启用了非CA中心签名的证书;客户端使用错误的CA中心公钥.
解决方法: 确保服务段使用了正确的公私钥, 确保客户端倒入了正确的CA中心证书.

查看Firefox证书的证书,如果发行信息如下,则表示启用系统自带的localhost证书
(/etc/pki/tls/certs/locahost.crt, /etc/pki/tls/private/locahost.key)
 OU = SomeOrganizationalUnit O = SomeOrganization L = SomeCity S = SomeState
解决方法是注释掉/etc/httpd/conf.d/ssl里面有关这对自带公私钥的两行或者将VirtualHost后面的*改为具体IP地址.


REF:
1. VirtualHost Examples
http://httpd.apache.org/docs/2.2/vhosts/examples.html

原创粉丝点击