http虚拟目录及https

虚拟目录标识方式:

不同IP
不同端口
不同域名
#2.2版本之前的需要注释掉中心主机DocumentRoot,不然会引起冲突

虚拟主机案例

1.基于不同IP的虚拟主机
NameVirtualHost 192.168.88.1
<Virtualhost 192.168.88.1>
        ServerName     www.luyubo1.com
        DocumentRoot "/home/httpd/luyubo1"
<Directory "/home/httpd/luyubo1" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>
<Virtualhost 192.168.88.2>
        ServerName     www.luyubo1.com
        DocumentRoot "/home/httpd/luyubo2"
<Directory "/home/httpd/luyubo2" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>
<Virtualhost 192.168.88.3>
        ServerName     www.luyubo1.com
        DocumentRoot "/home/httpd/luyubo3"
<Directory "/home/httpd/luyubo3" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>

查看基于不同IP的效果截图

1478096222766786.png

1478096222342329.png

1478096222482224.png

2.基于不同端口的虚拟主机
NameVirtualHost 192.168.88.1:80
listen 8080
listen 8088
<Virtualhost 192.168.88.1:80>
        ServerName     www.luyubo1.com
        DocumentRoot "/home/httpd/luyubo1"
<Directory "/home/httpd/luyubo1" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>
<Virtualhost 192.168.88.2:8080>
        ServerName     www.luyubo1.com
        DocumentRoot "/home/httpd/luyubo2"
<Directory "/home/httpd/luyubo2" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>
<Virtualhost 192.168.88.3:8088>
        ServerName     www.luyubo1.com
        DocumentRoot "/home/httpd/luyubo3"
<Directory "/home/httpd/luyubo3" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

查看基于不同端口的效果截图

1478096234646414.png

1478096234798265.png

1478096234238283.png

3.基于不同域名的虚拟主机
<Virtualhost 192.168.88.1>
        ServerName     www.luyubo1.com
        DocumentRoot "/home/httpd/luyubo1"
<Directory "/home/httpd/luyubo1" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>
<Virtualhost 192.168.88.1>
        ServerName     www.luyubo2.com
        DocumentRoot "/home/httpd/luyubo2"
<Directory "/home/httpd/luyubo2" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>
<Virtualhost 192.168.88.1>
        ServerName     www.luyubo3.com
        DocumentRoot "/home/httpd/luyubo3"
<Directory "/home/httpd/luyubo3" >
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
</Virtualhost>

查看基于不同域名的虚拟主机的效果截图

1478096275347101.png

1478096275575847.png

1478096275421830.png

https协议

HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。

http和https的区别

超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息。HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果***者截取了Web浏览器和网站服务器之间的传输报文,就可以直接读懂其中的信息,因此HTTP协议不适合传输一些敏感信息,比如信用卡号、密码等。 
为了解决HTTP协议的这一缺陷,需要使用另一种协议:安全套接字层超文本传输协议HTTPS。为了数据传输的安全,HTTPS在HTTP的基础上加入了SSL协议,SSL依靠证书来验证服务器的身份,并为浏览器和服务器之间的通信加密。

SSL会话的简化过程

(1) 客户端发送可供选择的加密方式,并向服务器请求证书;
(2) 服务器端发送证书以及选定的加密方式给客户端;
(3) 客户端取得证书并进行证书验正:
   如果信任给其发证书的CA:
       (a) 验正证书来源的合法性;用CA的公钥解密证书上数字签名;
       (b) 验正证书的内容的合法性:完整性验正
       (c) 检查证书的有效期限;
       (d) 检查证书是否被吊销;
       (e) 证书中拥有者的名字,与访问的目标主机要一致;
(4) 客户端生成临时会话密钥(对称密钥),并使用服务器端的公钥加密此数据发送给服务器,完成密钥交换;
(5) 服务用此密钥加密用户请求的资源,响应给客户端;

注意:SSL会话是基于IP地址创建;所以单IP的主机上,仅可以使用一个https虚拟主机;

配置httpd支持https

(1) 为服务器申请数字证书;
   测试:通过私建CA发证书
       (a) 创建私有CA
       (b) 在服务器创建证书签署请求
       (c) CA签证

(2) 配置httpd支持使用ssl,及使用的证书;
   # yum -y install mod_ssl

   配置文件:/etc/httpd/conf.d/ssl.conf
       DocumentRoot
       ServerName
       SSLCertificateFile
       SSLCertificateKeyFile

自建CA并签发证书

首先安装mod_ssl包,配置http支持https
yum -y install mod_ssl
httpd -M | grep ssl
ssl_module (shared)
  1. 生成CA私钥 

(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

1.png

2.生成自签证书 
openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365

2.png

3.创建CA所需目录和文件 
mkdir –pv /etc/pki/CA/{certs,crl,newcerts} 
touch /etc/pki/CA/{serial,index.txt}

4.写入CA申请编号 
echo 01 > /etc/pki/CA/serial

1.在web上面生成私钥 
(umask 077; openssl genrsa -out httpd.key 2048)

2.在web上面申请CA认证 
openssl req -new -key httpd.key -out httpd.csr -days 365

3.png

在CA上面签署web申请的认证请求

  1. 把httpd的httpd.csr发给CA在CA机器上面完成认证请求

  2. 在CA机器上面完成签署 
    openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365

    4.png

  3. 把签署好的httpd.crt发给web服务器,并在本地安装CA的自签证书

  4. 本地安装cacert.pem证书,在后面加上crt后缀即可

    5.png

  5. 本地安装证书

    6.png

7.png

配置证书位置/etc/httpd/conf.d/ssl.conf

8.png

浏览器测试访问正常

9.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章