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


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