http虛擬目錄及https

來源:互聯網
上載者:User

標籤:虛擬機器主機   https   httpd   apache   

虛擬目錄標識方式:
不同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的效果

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096222766786.png" title="1478096222766786.png" alt="1478096222766786.png" />

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096222342329.png" title="1478096222342329.png" alt="1478096222342329.png" />

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096222482224.png" title="1478096222482224.png" alt="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>

查看基於不同連接埠的效果

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096234646414.png" title="1478096234646414.png" alt="1478096234646414.png" />

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096234798265.png" title="1478096234798265.png" alt="1478096234798265.png" />

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096234238283.png" title="1478096234238283.png" alt="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>

查看基於不同網域名稱的虛擬機器主機的效果

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096275347101.png" title="1478096275347101.png" alt="1478096275347101.png" />

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096275575847.png" title="1478096275575847.png" alt="1478096275575847.png" />

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096275421830.png" title="1478096275421830.png" alt="1478096275421830.png" />

https協議
HTTPS(全稱:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全為目標的HTTP通道,簡單講是HTTP的安全版。即HTTP下加入SSL層,HTTPS的安全基礎是SSL,因此加密的詳細內容就需要SSL。
http和https的區別
超文字傳輸通訊協定 (HTTP)HTTP協議被用於在Web瀏覽器和網站伺服器之間傳遞資訊。HTTP協議以明文方式發送內容,不提供任何方式的資料加密,如果攻擊者截取了Web瀏覽器和網站伺服器之間的傳輸報文,就可以直接讀懂其中的資訊,因此HTTP協議不適合傳輸一些敏感資訊,比如信用卡號、密碼等。 
為瞭解決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)

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096879160643.png" title="1478096879160643.png" alt="1.png" />

2.產生自簽認證 
openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 365

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096886301253.png" title="1478096886301253.png" alt="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

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096906350139.png" title="1478096906350139.png" alt="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

    650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096917371209.png" title="1478096917371209.png" alt="4.png" />

  3. 把簽署好的httpd.crt發給web伺服器,並在本地安裝CA的自簽認證

  4. 本地安裝cacert.pem認證,在後面加上crt尾碼即可

    650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096924774702.png" title="1478096924774702.png" alt="5.png" />

  5. 本地安裝認證

    650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096934474306.png" title="1478096934474306.png" alt="6.png" />

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096947475552.png" title="1478096947475552.png" alt="7.png" />

配置認證位置/etc/httpd/conf.d/ssl.conf

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096966176387.png" title="1478096966176387.png" alt="8.png" />

瀏覽器測試訪問正常

650) this.width=650;" src="http://www.178linux.com/ueditor/php/upload/image/20161102/1478096975709554.png" title="1478096975709554.png" alt="9.png" />


本文出自 “Linux學習之路” 部落格,請務必保留此出處http://luyubo.blog.51cto.com/7634254/1868736

http虛擬目錄及https

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.