天天看點

wampserver 配置https證書

author:he

qq:760863706

wamp:2.5 ,3.0.6

date:2018-10-23

讓wamp具有HTTPS通路權限,需要配置安全協定證書,本文參考 https://www.youtube.com/watch?v=TH6evGKgy20 視訊内容,并在本地 wamp2.5 和 wamp3.0.6 兩個伺服器上配置測試,都能滿足需求,現做一下記錄,以備後續查詢

1:下載下傳openssl.exe

在網站 https://slproweb.com/products/Win32OpenSSL.html 下載下傳對應自己作業系統的軟體,然後安裝

wampserver 配置https證書

2:cmd下執行指令

結合本機,cmd下切換到 D:\wamp\bin\apache\apache2.4.9\bin,然後依次執行執行

openssl genrsa -aes256 -out private.key 2048
openssl rsa -in private.key -out private.key
openssl req -new -x509 -nodes -sha1 -key private.key -out certificate.crt -days 36500 -config D:\wamp\bin\apache\apache2.4.9\conf\openssl.cnf
           

執行指令期間,會讓輸入密碼,或者國家地區一類的 ,按提示輸入即可,執行結束後會在 D:\wamp\bin\apache\apache2.4.9\bin 目錄下生成 certificate.crt 和 private.key 兩個檔案,複制這兩個檔案,然後切換目錄到 D:\wamp\bin\apache\apache2.4.9\conf 下,建立key檔案夾,放入這兩個檔案

3:配置更改

打開apache 配置檔案, D:\wamp\bin\apache\apache2.4.9\conf\httpd.conf,修改3項内容,去除預設的 #

Include conf/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
           

然後打開配置檔案 D:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-ssl.conf ,在原預設配置中做如下修改

DocumentRoot "D:/wamp/www"
ServerName localhost:443
ServerAdmin [email protected]
ErrorLog "D:/wamp/bin/apache/apache2.4.9/logs/error.log"
TransferLog "D:/wamp/bin/apache/apache2.4.9/logs/access.log"

SSLCertificateFile "D:/wamp/bin/apache/apache2.4.9/conf/key/certificate.crt"
SSLCertificateKeyFile "D:/wamp/bin/apache/apache2.4.9/conf/key/private.key"

CustomLog "D:/wamp/bin/apache/apache2.4.9/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
           

完成配置後,在保證php.ini中的 extension=php_openssl.dll 引入的情況下,重新開機伺服器,然後浏覽器輸入 https://localhost:443 即可通過https通路我們的網站了,在wamp3.0.6 的情況下配置流程是一樣的 ,隻是 在修改 httpd-ssl.conf 這個檔案時把預設路徑更改為伺服器實際的路徑就可以了