隨著網絡技術的發展,人們對信息安全越來越重視,傳統的http瀏覽互聯網的方式由于未經加密,其安全性廣為人們詬病,https協議作為加密的互聯網解決方案解決了這一問題。下面我就簡要說明下如何實現通過https發布web頁面的。
實驗目的:
模擬Centos6上安裝httpd2.4,并實現https加密訪問主頁
實驗器材:
Centos6.8虛擬機
實驗步驟:
1 生成自簽名證書
2 下載并編譯安裝httpd2.4及其相關組件
3 安裝ssl模塊并修改httpd配置文件
實驗過程:
1 生成自簽名證書
https協議是基于SSL協議的,在使用https協議之前首先要獲得SSL的CA證書,在生產情況下此證書需要向CA證書頒發機構購買,而在實驗環境下可以使用openssl工具生成自簽名證書。
1) 創建根CA證書
根CA證書是CA認證機構必須有的,在本實驗需要先創建此證書才能為自建網站頒發證書。
cd /etc/pki/CA/ #進入CA目錄 touch index.txt #創建index.txt文件,此文件記錄了根CA頒發的所有證書 echo 01 > serial #添加起始計數 (umask 077;openssl genrsa -out private/cakey.pem 4096)#生成私鑰 openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650 #生成根證書
2) 創建網站CA申請
(umask 066;openssl genrsa -out private/client.key 1024) #生成私鑰 openssl req -new -key private/client.key -days 356 -out client.csr #通過私鑰生成證書申請文件
3) 申請網站CA證書
openssl ca -in client.csr -out certs/client.cer
至此,網站的CA證書創建完成,證書文件client.cer與私鑰client.key備用
2 下載并編譯安裝httpd2.4及其相關組件
安裝httpd2.4需要的組件包括apr-1.5.0、apr-util-1.5.3、httpd-2.4.10、pcre及openssl-devel
1) 下載編譯安裝apr-1.5.0
wget http://archive.apache.org/dist/apr/apr-1.5.0.tar.gz tar xf apr-1.5.0.tar.gz cd apr-1.5.0 ./configure --prefix=/usr/local/apr make && make install
2)下載編譯安裝apr-util-1.5.3
wget http://archive.apache.org/dist/apr/apr-util-1.5.3.tar.gz tar xf apr-util-1.5.3.tar.gz cd apr-util-1.5.3 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ make && make install
4) 安裝pcre及openssl-devel
yum install -y pcre-devel yum install –y openssl-devel
5) 下載編譯安裝httpd-2.4.10
wget http://archive.apache.org/dist/httpd/httpd-2.4.10.tar.gz tar xf httpd-2.4.10.tar.gz cd httpd-2.4.10 ./configure --prefix=/usr/local/apache24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpm-shared=all --with-mpm=prefork make && make install
3 安裝ssl模塊并修改httpd配置文件
1) 安裝ssl模塊
yum install mod_ssl -y httpd -M | grep ssl #查看模塊安裝情況
2)修改配置文件/usr/local/apache24/conf/httpd.conf
LoadModule ssl_module modules/mod_ssl.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so Include conf/extra/httpd-ssl.conf
3)修改配置文件/usr/local/apach24/conf/extra/httpd-ssl.conf
DocumentRoot "/var/www/html" ServerName www.magedu.com SSLCertificateFile /usr/local/apach24/ssl/client.csr SSLCertificateKeyFile /usr/local/apach24/ssl/client.key
4)修改域名
ServerName www.magedu.com:443
重啟服務
/usr/local/apache24/bin/apachectl restart
原創文章,作者:realmaster,如若轉載,請注明出處:http://www.www58058.com/73814