
我先启动一下 CentOS5.1 Linux
如果你要架设一台安全性比较的web服务器,例如:
比如银行、证券、购物等,都采用HTTPS服务,这样在这些网站上的交换信息其他人都无法看到,保证了交易
的安全性。
如果你有留意的话,网页的地址以https:// 开始,而不是一般的http:// 开始
采用HTTPS服务其实就是 通过SSL(安全套接字层)来保证安全性的。
好了, 下面我们来视频演示 配置一台支持ssl安全性比较高的apache web服务器
我是用的系统是 CentOS5.1 apache2.2.8 ,前提你必须安装好apache 而且支持 ssl
如果你不会编译安装 httpd-2.2.8 和支持ssl, 建议你看这一篇文章, 视频入门教程安装 apache 2.2.8
http://www.17rumen.com/archives/20.html
现在来 下载ssl和使用
下载地址 http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
#wget http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
解压缩
#tar xvzf ssl.ca-0.1.tar.gz
进入目录
#cd ssl.ca-0.1
开始生成证书
[root@localhost ssl.ca-0.1]# ./new-root-ca.sh (生成根证书)
No Root CA key round. Generating one
Generating RSA private key, 1024 bit long modulus
............................++++++
...........++++++
e is 65537 (0x10001)
Enter pass phrase for ca.key:1234 (输入一个密码,最少4位)
Verifying - Enter pass phrase for ca.key:1234 (再输入一次密码,跟刚才的一样)
Self-sign the root CA...(签署根证书)
Enter pass phrase for ca.key:1234(输入刚刚设置的密码)
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) [MY]:CN
State or Province Name (full name) [Perak]:China
Locality Name (eg, city) [Sitiawan]:Guangzhou
Organization Name (eg, company) [My Directory Sdn Bhd]:17rumen.com
Organizational Unit Name (eg, section) [Certification Services Division]:17rumen
Common Name (eg, MD Root CA) []:name1
Email Address []:17rumen@gmail.com
这样就生成了ca.key和ca.crt两个文件,
[root@localhost ssl.ca-0.1]# ls ca* 查看一下是否存在
ca.crt ca.key
--------------------------------------
下面还要为服务器生成一个证书,也就是要部署到apache的证书:
[root@localhost ssl.ca-0.1]# ./new-server-cert.sh server (这个证书的名字是server,当然,你也可
以随便写)
No server.key round. Generating one
Generating RSA private key, 1024 bit long modulus
.....++++++
.....++++++
e is 65537 (0x10001)
Fill in certificate data
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) [MY]:CN
State or Province Name (full name) [Perak]:China
Locality Name (eg, city) [Sitiawan]:Guangzhou
Organization Name (eg, company) [My Directory Sdn Bhd]:17rumen.com
Organizational Unit Name (eg, section) [Secure Web Server]:17rumen
Common Name (eg, www.domain.com) []:name2
Email Address []:17rumen@gmail.com
You may now run ./sign-server-cert.sh to get it signed
这样就生成了server.csr和server.key这两个文件。
]# ls server* 同样查看一下是否存在
====================================
必须签署一下才能使用的:
[root@localhost ssl.ca-0.1]# ./sign-server-cert.sh server
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for ./ca.key:1234(我们开始设置的密码)
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'China'
localityName :PRINTABLE:'Guangzhou'
organizationName :PRINTABLE:'17rumen.com'
organizationalUnitName:PRINTABLE:'17rumen'
commonName :PRINTABLE:'name2'
emailAddress :IA5STRING:'17rumen@gmail.com'
Certificate is to be certified until May 4 16:57:31 2009 GMT (365 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
CA verifying: server.crt <-> CA cert
server.crt: OK
===============================
下面修改一下 apache 的配置 ]# vi /etc/httpd.conf
修改前:
# Secure (SSL/TLS) connections
# Include /etc/extra/httpd-ssl.conf
去掉 # 修改后:
# Secure (SSL/TLS) connections
Include /etc/extra/httpd-ssl.conf
保存 退出
可以说 apache httpd-2.2.8 真的很方便, 只需要去掉那一行注释就可以使用 ssl 了
但是在编译安装时候一定要 加入 -enable-ssl
----------------------------
把 server.crt server.key 拷贝到 /etc 目录下
[root@localhost ssl.ca-0.1]# cp server.crt /etc/server.crt
[root@localhost ssl.ca-0.1]# cp server.key /etc/server.key
关闭 apache
[root@localhost ssl.ca-0.1]# /usr/local/apache2/bin/apachectl stop &
再启动 apache
[root@localhost ssl.ca-0.1]# /usr/local/apache2/bin/apachectl start &
]# netstat -tnl
可以看到 除了80 端口,还有一个443端口
443端口即网页浏览端口,主要是用于HTTPS服务,是提供加密和通过安全端口传输的另一种HTTP
我们对比一下来访问服务器的网页
1, 我们按照常见的方式来访问 http://192.168.1.118
2, 我们使用ssl加密的方式来访问 https://192.168.1.118
看到了吧,弹出一个 安全警告,
我们查看一下 证书,证书这里有些内容使我们刚才设置的
我们点击 是
可以看到浏览器 下面多了一个锁的东西, 把鼠标放过去,显示
可靠的SSL(128 位)
好了基本就演示到这里。 谢谢大家支持,
如果有什么宝贵建议或者遇到什么问题,欢迎大家对文章评论支持。谢谢
04月 11th, 2009 at 10:52:27 #肖斓
我想请问下使用:yum -y install openssl-devel一直报错之后,是不是只有自己去下载那个包安装..但是找了很多网站,都没有那个包
[回复]
04月 12th, 2009 at 12:09:28 #admin
http://www.verycd.com/topics/2738557/
可以到这里下载,由于网站最近提供的下载超出了流量,暂时不提供。
[回复]
07月 18th, 2009 at 20:39:17 #admin
不会是浏览器问题吧,确定一下 配置是否正确。
[回复]
12月 8th, 2009 at 18:04:25 #baicai
上面教程上说!在http.conf里,设置SSL时,要在编绎安装apache时要 -enable-ssl
但是我在安装的时候没有加载这项,安装完之后还能加载吗?如何载入?
我最后一直在看你的教程,先对你说声谢谢 , 可否留个QQ 也好及时请教!
[回复]
adminreply on 2009-12-09 18:20:16:
呵呵,这个我没有试过,不过应该是可以的,apache还是比较灵活的。
12月 9th, 2009 at 15:09:07 #baicai
我的都以设置完成! 但是进入到网页的时候还是http:// 而不是https://
根据教程没有!出现错误
[回复]
adminreply on 2009-12-09 18:17:48:
https 自己手工输入 看看。
08月 15th, 2010 at 22:58:23 #匿名
按照教程操作后,网页访问不了,没有提示证书,Internet Explorer 无法显示该网页
[回复]
adminreply on 2010-08-16 17:04:09:
请检查一下哪个步骤出错了。