导读 Web服务器在默认情况下使用HTTP,这是一个纯文本的协议。正如其名称所暗示的,纯文本协议不会对传输中的数据进行任何形式的加密。而基于HTTP的Web服务器是非常容易配置,它在安全方面有重大缺陷。

任何”中间人”,通过精心防止的数据包嗅探器,是能够看到任何经过的数据包内容。更进一步,恶意用户甚至可以在传输路径设置一个假冒的WEB服务器冒名顶替实际的目标Web服务器。在这种情况下,最终用户可能实际上与假冒者服务器,而不是真正的目的服务器进行通信。这样,恶意用户可以通过精心设计的表单欺骗终端用户获取到敏感信息,如用户名密码。


为了处理这些类型的漏洞,大多数供应商往往在他们的web服务器应用HTTPS协议。对于只读类型的网站,用户只能读取内容,并没有实际提交任何信息,HTTP仍然是一个可行的选择。但是,对于保存敏感信息的网站,比如:用户需要登录来获得网站的服务,那么HTTPS是必须的。

接下来演示一下配置https访问www

首先安装httpd服务
[root@localhost ~]# yum install httpd -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-67.el7.centos 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-67.el7.centos,它被软件包 httpd-2.4.6-67.el7.centos.x86_64 需要
--> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-67.el7.centos.x86_64 需要
--> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-67.el7.centos.x86_64 需要
--> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-67.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 apr.x86_64.0.1.4.8-3.el7 将被 安装
---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装
---> 软件包 httpd-tools.x86_64.0.2.4.6-67.el7.centos 将被 安装
---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

========================================================================================================================================================================
 Package                                  架构                                版本                                               源                                大小
========================================================================================================================================================================
正在安装:
 httpd                                    x86_64                              2.4.6-67.el7.centos                                123                              2.7 M
为依赖而安装:
 apr                                      x86_64                              1.4.8-3.el7                                        123                              103 k
 apr-util                                 x86_64                              1.5.2-6.el7                                        123                               92 k
 httpd-tools                              x86_64                              2.4.6-67.el7.centos                                123                               87 k
 mailcap                                  noarch                              2.1.41-2.el7                                       123                               31 k

事务概要
========================================================================================================================================================================
安装  1 软件包 (+4 依赖软件包)

总下载量:3.0 M
安装大小:10 M
Downloading packages:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                    9.0 MB/s | 3.0 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : apr-1.4.8-3.el7.x86_64                                                                                                                              1/5 
  正在安装    : apr-util-1.5.2-6.el7.x86_64                                                                                                                         2/5 
  正在安装    : httpd-tools-2.4.6-67.el7.centos.x86_64                                                                                                              3/5 
  正在安装    : mailcap-2.1.41-2.el7.noarch                                                                                                                         4/5 
  正在安装    : httpd-2.4.6-67.el7.centos.x86_64                                                                                                                    5/5 
  验证中      : httpd-2.4.6-67.el7.centos.x86_64                                                                                                                    1/5 
  验证中      : mailcap-2.1.41-2.el7.noarch                                                                                                                         2/5 
  验证中      : apr-1.4.8-3.el7.x86_64                                                                                                                              3/5 
  验证中      : httpd-tools-2.4.6-67.el7.centos.x86_64                                                                                                              4/5 
  验证中      : apr-util-1.5.2-6.el7.x86_64                                                                                                                         5/5 

已安装:
  httpd.x86_64 0:2.4.6-67.el7.centos                                                                                                                                    

作为依赖被安装:
  apr.x86_64 0:1.4.8-3.el7           apr-util.x86_64 0:1.5.2-6.el7           httpd-tools.x86_64 0:2.4.6-67.el7.centos           mailcap.noarch 0:2.1.41-2.el7          

完毕!
[root@localhost ~]# rpm -qa|grep httpd
httpd-2.4.6-67.el7.centos.x86_64
httpd-tools-2.4.6-67.el7.centos.x86_64
测试主页

创建主页
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# echo "this is a test" >index.html
[root@localhost html]# curl 172.16.1.10
this is a test
安装相应支持模块
[root@localhost html]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost html]# cd /mnt/Packages/
[root@localhost Packages]# rpm -ivh mod_ssl-2.4.6-67.el7.centos.x86_64.rpm 
警告:mod_ssl-2.4.6-67.el7.centos.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mod_ssl-1:2.4.6-67.el7.centos    ################################# [100%]

安装完成后在/etc/httpd/conf.d会出现ssl.conf文件

建立http使用的私钥
[root@localhost Packages]# cd /etc/pki/tls/certs
[root@localhost certs]# make myhttpd.key
umask 77 ; \
/usr/bin/openssl genrsa -aes128 2048 > myhttpd.key
Generating RSA private key, 2048 bit long modulus
............+++
...+++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
[root@localhost certs]# mv myhttpd.key myhttpd.key.raw
[root@localhost certs]# openssl rsa -in myhttpd.key.raw -out myhttpd.key
Enter pass phrase for myhttpd.key.raw:
writing RSA key
[root@localhost certs]#  rm -f myhttpd.key.raw
[root@localhost certs]#  chmod 400 myhttpd.key
[root@localhost certs]#  make myhttpd.crt SERIAL=2015060201
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key myhttpd.key -x509 -days 365 -out myhttpd.crt  -set_serial 2015060201
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
string is too long, it needs to be less than  2 bytes long
Country Name (2 letter code) [XX]:ccc
string is too long, it needs to be less than  2 bytes long
Country Name (2 letter code) [XX]:c
string is too short, it needs to be at least 2 bytes long
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:hb
Locality Name (eg, city) [Default City]:bd
Organization Name (eg, company) [Default Company Ltd]:ssss
Organizational Unit Name (eg, section) []:info
Common Name (eg, your name or your server's hostname) []:ssss
Email Address []:sss
[root@localhost certs]# vim /etc/httpd/conf.d/ssl.conf
[root@localhost certs]#  cp myhttpd.key /etc/pki/tls/private/
重启httpd
[root@localhost certs]# systemctl restart httpd
测试

选中高级,添加例外



由此,https访问httpd就实现了

本文原创地址:https://www.linuxprobe.com/https-www.html编辑:王华超,审核员:刘遄