一:https簡介:
http傳輸協定傳輸資料是以明文的方式傳送的,是以使用者的任何資料封包都可能被監聽竊取,為了提高系統的安全性,需要用到https協定,這樣方式采用了
ssl(安全套接字層)加密機制。ssl利用非配對的key pair(公鑰和私鑰)來組成密鑰,然後使用公鑰加密後傳輸,目标主機再以私鑰來解密,這樣在internet
上傳輸的資料為密文,這些資料就相對安全。要使用安全協定,www伺服器就必須要啟動https傳輸協定,而浏覽器必須在網址列輸入https://開頭的網址,
兩者才能夠進行溝通和聯機。
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557514Ogxl.png"></a>
二:CA介紹:
CA是一個公認的公正機關,使用者可以向其注冊一個public key,用戶端浏覽器在浏覽資源時,會主動的向CA機關确認該public key是否為合法注冊過的,如
果是則該次聯機才會建立,如果不是,浏覽器就會發出警告資訊。
三:web伺服器類型:
www伺服器的類型有www平台和網頁程式語言與資料庫(lamp)。而目前www伺服器軟體主要有apache和iis。apache是自由軟體,可以在任何作業系統上
安裝,iis是windows下的,僅能在windows作業系統上安裝與執行。
案例一:在Linux上安裝apache,建立openCA向伺服器頒發證書,實作用戶端使用https向web伺服器的請求。
一:架構CA伺服器:
1:[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm
2:[root@localhost Server]# cd /etc/pki/
[root@localhost pki]# vim tls/openssl.cnf #編輯該文家如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557520gu9e.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557521RMOv.png"></a>
[root@localhost CA]# mkdir crl #放置證書吊銷清單
[root@localhost CA]# mkdir certs #已經發行過的證書存放的位置
[root@localhost CA]# mkdir newcerts #新發行的證書存放位置
[root@localhost CA]# touch serial #頒發證書的初始值
[root@localhost CA]# echo "01"&gt;serial #将01賦予serial,作為初始值
[root@localhost CA]# touch index.txt #資料庫的索引檔案
[root@localhost CA]# openssl genrsa 1024 &gt;private/cakey.pem #利用1024的非對稱加密算法rsa,算出一個密鑰放置在cakey.com檔案中
[root@localhost CA]# chmod 600 private/cakey.pem #将cakey.com檔案設定為600
[root@localhost CA]# openssl req -new -key private/cakey.pem -x509 -out cacert.pem -days 3650 #利用自己的私鑰為自己(CA伺服器)産
生一個證書叫cacert.pem。-x509表示證書類型,證書有效時間3650天,-out表示輸出 如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557528PklG.png"></a>
二:配置web伺服器:
1:[root@localhost pki]# mkdir -pv /etc/httpd/certs #建立一個存放私鑰,證書請求,申請證書的檔案
[root@localhost pki]# cd /etc/httpd/certs/
[root@localhost certs]# openssl genrsa 1024 &gt;httpd.key #使用長度為1024的非對稱加密算法rsa,重定向到存放私鑰的檔案httpd.key中
[root@localhost certs]# chmod 600 httpd.key #修改httpd.key的權限為600,隻有目前使用者為可讀可寫,組使用者及其他使用者都無任何權限
[root@localhost certs]# openssl req -new -key httpd.key -out httpd.csr #利用存放私鑰的檔案httpd.key請求得到一個證書請求,請求産生的文
件叫httpd.csr
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557531Xght.png"></a>
[root@localhost certs]# openssl ca -in httpd.csr -out httpd.cert #利用ca産生一個證書,請求檔案是目前目錄下的httpd.csr,申請一個證書
httpd.cert
[root@localhost certs]# chmod 600 * #将所有檔案的權限改為600,隻允許目前使用者為可讀可寫,組使用者及其他使用者都無任何權限
2:[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo #編輯yum伺服器,如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_13455575345nEf.png"></a>
[root@localhost Server]# yum install mod_ssl #使用yum安裝httpds和ssl結合的子產品檔案mod_ssl
[root@localhost Server]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# cp -p ssl.conf ssl.conf.bak #将ssl.conf檔案備份一下
[root@localhost conf.d]# vim ssl.conf #編輯該檔案,如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642524vkAa.png"></a>
3:[root@localhost conf.d]# service httpd configtest #檢查httpd配置檔案的文法
[root@localhost conf.d]# service httpd restart
[root@localhost conf.d]# netstat -tupln |grep httpd #檢視http伺服器的端口是否啟動
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557539X5WG.png"></a>
[root@localhost pki]# vim /var/www/html/index.html #編輯頁面如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557540wBl2.png"></a>
[root@localhost pki]# service httpd restart
4:用windows xp主機進行測試。檢視https是否能用:
5:[root@localhost conf.d]# vim ssl.conf #如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_13456425271Yld.png"></a>
6:
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557552Bfr2.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642530U73L.png"></a>
檢視證書的頒發機構:
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642534zrhM.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557560hfEL.png"></a>
7:上一步驟中,顯示“安全證書上的名稱無效,或者與站點名稱不比對”,可以做如下修改:
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_13455575620b9q.png"></a>
然後使用主機名稱登陸:
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_13455575656JMa.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/21/5493845_1345557567IHaG.png"></a>
案例二:建立三個站點,基于ip位址的虛拟主機,主站點使用http通路,技術部tec和市場部mkt使用https通路。需要為tec和mkt向CA伺服器請求兩個證書。
一:首先從CA伺服器上申請證書:(此案例需要申請一個證書,另外一個證書使用案例一的)
1:[root@localhost ~]# mkdir /mnt/cdrom/
[root@localhost ~]# mkdir /etc/httpd/certs111 #建立一個存放私鑰,證書請求,申請證書的目錄
[root@localhost ~]# cd /etc/httpd/certs111/
[root@localhost certs111]# openssl genrsa 1024 &gt;httpd.key111 #利用1024為非對稱加密算法rsa,得到一個私鑰,存放在httpd.key111檔案中
[root@localhost certs111]# openssl req -new -key httpd.key111 -out httpd.csr111 #利用存放私鑰的檔案求httpd.key111請得到一個證書請求,請求産生的檔案叫httpd.csr111 ,如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642543epF6.png"></a>
[root@localhost certs111]# openssl ca -in httpd.csr111 -out httpd.cert111 #利用ca産生一個證書,請求檔案是目前目錄下的httpd.csr111,申請一個證書httpd.cert111
[root@localhost certs111]# chmod 600 * #将所有檔案的權限改為600,隻允許目前使用者為可讀可寫,組使用者及其他使用者都無任何權限
[root@localhost certs111]# yum install mod_ssl #使用yum安裝httpds和ssl結合的子產品檔案mod_ssl
[root@localhost certs111]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# vim ssl.conf #編輯該檔案,如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642546HRK7.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642552PbFu.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642557RLFg.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642563pnF6.png"></a>
二:建立基于ip位址的虛拟主機:
1:[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# ifconfig eth0:1 192.168.101.36 #為網卡eth0添加ip位址
[root@localhost Server]# ifconfig eth0:2 192.168.101.46 #為網卡eth0添加ip位址
[root@localhost www]# mkdir tec #建立目錄tec,用于存放tec站點的網頁
[root@localhost www]# mkdir mkt #建立目錄mkt,用于存放mkt站點的網頁
[root@localhost www]# vim tec/index.html #編輯網頁
[root@localhost www]# vim mkt/index.html
[root@localhost www]#vim /etc/httpd/conf/httpd.conf #修改配置檔案如圖:
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642567jNzw.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642570NsDZ.png"></a>
測試:站點首頁:
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642576Lnoi.png"></a>
測試:tec站點:監聽443端口
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642580w7H8.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642586hAbc.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642589raRl.png"></a>
測試:mkt站點:監聽443端口
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642592REKV.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_1345642596R2fP.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201208/22/5493845_13456426017CgM.png"></a>
本文轉自 liuyatao666 51CTO部落格,原文連結:http://blog.51cto.com/5503845/968688,如需轉載請自行聯系原作者