配置Apache服務器支持https協議和SSL證書,最基本的要求是Apache包含openssl模塊。還好apache/bin目錄下有libeay32.dll
、openssl.exe
、ssleay32.dll
,自帶了ssl模塊,若沒有該模塊,需自行下載單獨的openssl。php
啓動模塊比較簡單,打開apache的配置文件conf/httpd.conf,去掉ssl模塊前面的#css
LoadModule ssl_module modules/mod_ssl.so ... Include conf/extra/httpd-ssl.conf
若是你有證書了,那麼會有malinlin.cn.crt
malinlin.cn.key
,兩個文件,在conf下創建個ssl文件夾存放證書。將原先conf/extra/httpd-ssl.conf
備份後,新建一個httpd-ssl.conf
。如下是我爲蛋總配置的:git
Listen 443 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLPassPhraseDialog builtin <VirtualHost *:443> DocumentRoot "c:/wamp/www" ServerName malinlin.cn:443 ServerAdmin admin@example.com ErrorLog "C:/wamp/bin/apache/apache2.2.22/logs/ssl-error.log" TransferLog "C:/wamp/bin/apache/apache2.2.22/logs/sll-access.log" SSLEngine on SSLCertificateFile "C:/wamp/bin/apache/apache2.2.22/conf/ssl/malinlin.cn.crt" SSLCertificateKeyFile "C:/wamp/bin/apache/apache2.2.22/conf/ssl/malinlin.cn.key" SSLCertificateChainFile "C:/wamp/bin/apache/apache2.2.22/conf/ssl/malinlin.cn.crt" </VirtualHost>
若是想在原先httpd-sll.conf修改也行,記得將這三行註釋掉。沒有註釋的話啓動wamp會是失敗的枯黃色。算法
#SSLSessionCache "dbm:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache" #SSLSessionCache "shmcb:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache(512000)" #SSLSessionCacheTimeout 300
配置好後重啓wamp,重啓完畢後,瀏覽器就能夠訪問了。apache
若是到這已經解決你的問題了,那就不必往下看了,下面是介紹沒有證書的狀況下也能體驗,咱們強大的openssl也是能夠生成證書的,以後訪問https://localhost
(哎,什麼域名都是ok的啦)vim
由於該目錄纔有libeay32.dll
、openssl.exe
、ssleay32.dll
等文件。瀏覽器
使用DOS命令在bin目錄下執行命令:set OPENSSL_CONF=..\conf\openssl.cnf,經過此命令設置openssl的環境變量,若是不執行此命令,後面的操做會報錯。服務器
set OPENSSL_CONF=..\conf\openssl.cnf
DOS下執行命令:openssl genrsa 4096 > server.key,執行了這個命令,會在bin目錄下生成server.key。註釋:這是使用128位的RSA算法生成的密鑰,還可使用其餘的算法生成密鑰,相關的用法可使用搜索引擎搜索。4096是密鑰的長度,這個值最好使用4096以上的值,必須是2的整數次方。測試
openssl genrsa 4096 > server.key
DOS命令下執行:openssl req -new -key server.key > server.csr,這個命令使用生成的密鑰文件 server.key生成證書請求文件server.csr,執行這一命令以後,後面還要輸入不少參數。ui
openssl req -new -key server.key > server.csr Country Name (2 letter code) [AU]:CN ISO國家代碼(只支持兩位字符) State or Province Name (full name) [Some-State]:Hu Bei 所在省份 Locality Name (eg, city) []:Wu Han 所在城市 Organization Name (eg, company) [Internet Widgits Pty Ltd]:Mark Company 公司名稱 Organizational Unit Name (eg, section) []:IT 組織名稱 Common Name (e.g. server FQDN or YOUR name) []:www.phpmarker.com 申請證書的域名 Email Address []:phpmarker@163.com 管理員郵箱 Please enter the following ‘extra’ attributes to be sent with your certificate request A challenge password []: 交換密鑰 可空 An optional company name []: 可空
DOS命令下執行:openssl req -x509 -days 365 -key server.key -in server.csr > server.crt,這個命令使用第三步和第四步生成的密鑰和證書來生成證書server.crt,-days參數表示證書有效期,單位爲天,x509表示生成的是X.509證書。
openssl req -x509 -days 365 -key server.key -in server.csr > server.crt
DOS下執行命令:openssl x509 -noout -text -in server.crt,這個命令能夠查看證書的詳細信息
openssl x509 -noout -text -in server.crt
執行上面全部的命令以後,在Apache的bin目錄下生成了三個文件server.key
、server.csr
、server.crt
。能夠將其移動到專門放證書的文件夾。
修改httpd-ssl.conf,如下是個人配置:
Listen 443 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLPassPhraseDialog builtin #SSLSessionCache "dbm:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache" #SSLSessionCache "shmcb:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache(512000)" #SSLSessionCacheTimeout 300 <VirtualHost _default_:443> DocumentRoot "e:/kuaipan/code/win_www" ServerName localhost:443 ServerAdmin admin@example.com ErrorLog "D:/wamp/bin/apache/apache2.4.9/logs/ssl-error.log" TransferLog "D:/wamp/bin/apache/apache2.4.9/logs/sll-access.log" SSLEngine on SSLCertificateFile "D:/wamp/bin/apache/apache2.4.9/conf/ssl/server.crt" SSLCertificateKeyFile "D:/wamp/bin/apache/apache2.4.9/conf/ssl/server.key" SSLCertificateChainFile "D:/wamp/bin/apache/apache2.4.9/conf/ssl/server.crt" </VirtualHost>
重啓後瀏覽器訪問https://localhost
可用,可是https是個叉,不像上面的圖是綠色的。出現這種狀況,由於咱們本身製做的證書,不被瀏覽器所信賴。咱們查看證書詳細狀況: