Rootop 服务器运维与web架构

配置apache支持https加密安全登陆

| 暂无评论

      在我们现在使用的网上银行,关键web服务登陆时,都采用https方式登陆,它的数据传输采用的是加密方式,而http是明文,很容易在网络上嗅探到,原理不多说,下面说下怎样让apache支持https。

1、搭建一台ca证书服务器      172.17.1.115/25

2、申请证书,配置apache      172.17.1.118/25

ca服务器我是用的server2003搭建的,具体的搭建过程简单一提:

       在“添加删除windows组件”中,勾选“证书服务”和 应用程序服务器 中的“Internet信息服务(IIS)”,然后确定一路安装即可。

       在linux中安装openssl  mod_ssl两个包

[root@rhel6www ~]# yum install -y openssl mod_ssl

[root@rhel6www ~]# cd /etc/pki/tls/certs

[root@rhel6www certs]# make server.key    //首先生成一个server.key文件
umask 77 ; \
        /usr/bin/openssl genrsa -aes128 2048 > server.key
Generating RSA private key, 2048 bit long modulus
..+++
……………+++
e is 65537 (0x10001)
Enter pass phrase:     //输入一个密码
Verifying – Enter pass phrase:      //再次输入

[root@rhel6www certs]# make server.csr    //还需要一个生成一个文件,server.csr
umask 77 ; \
        /usr/bin/openssl req -utf8 -new -key server.key -out server.csr
Enter pass phrase for server.key:
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) []:sd
Locality Name (eg, city) [Default City]:qd
Organization Name (eg, company) [Default Company Ltd]:nq
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server’s hostname) []:www.rootop.org
Email Address []:venuslinux@gmail.com

Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:123qaz
An optional company name []:
[root@rhel6www certs]# ll
total 1232
-rw-r–r–. 1 root root 578465 Apr  7  2010 ca-bundle.crt
-rw-r–r–. 1 root root 658225 Apr  7  2010 ca-bundle.trust.crt
-rw——-. 1 root root   1188 May 30 08:03 localhost.crt
-rwxr-xr-x. 1 root root    610 Feb 10 10:27 make-dummy-cert
-rw-r–r–. 1 root root   2242 Feb 10 10:27 Makefile
-rw——-. 1 root root   1082 Jul  8 06:48 server.csr
-rw——-. 1 root root   1766 Jul  8 06:45 server.key

将server.csr文件拷贝到windows下,方便进行证书申请。
打开server.csr文件,推荐用notepad++这种编辑工具,否则用记事本打开会有“方块”,不能自动换行的问题,复制其中的内容。

然后访问我的ca服务器:http://172.17.1.115/certsrv/

点击“高级证书申请”

申请一个证书

使用base64编码的cmc或pkcs#10文件提交一个证书申请

粘贴刚才server.csr文件的内容

提交挂起后,等待ca服务器颁发证书

回到ca服务器,打开证书服务,可以看到提交的申请,右键,任务,颁发即可。

再次登陆ca服务器的web申请页面。

点击“查看挂起的证书申请的状态”就可以看到颁发的证书,下载下来即可。

然后将颁发的证书复制到linux中。

[root@rhel6www certs]# mv certnew.cer server.crt   //将生成的证书更名为server.crt

[root@rhel6www certs]# vi /etc/httpd/conf.d/ssl.conf    //修改以下两行如下

SSLCertificateFile /etc/pki/tls/certs/server.crt

SSLCertificateKeyFile /etc/pki/tls/certs/server.key

[root@rhel6www certs]# service httpd restart     //重启apache加载证书,并生效
Stopping httpd:                                            [FAILED]
Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
Apache/2.2.15 mod_ssl/2.2.15 (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 127.0.0.1:443 (RSA)
Enter pass phrase:                       //输入刚才键入的密码

OK: Pass Phrase Dialog successful.
                                                           [  OK  ]

当下次重启apache的时候,还是会提示要求输入密码,那我们再来配置下。

[root@rhel6www certs]# openssl rsa -in server.key -out server.key
Enter pass phrase for server.key:          //输入之前的密码
writing RSA key
[root@rhel6www certs]#
以后就不会提示了。

然后再次访问linux服务器,可以看到http方式可以访问,https方式也是没问题的可以。

为什么我们不强制全部使用https方式登陆呢?比如说,在用户身份认证的时候,我们可以用加密的数据在网络间进行传输,在浏览网站的时候大都是文字,图片之类的就没必要再用https方式了。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/639.html

作者:Venus

服务器运维与性能优化

发表回复