天天看點

Apache配置SSLApache配置SSL

Apache配置SSL

第一步

在httpd.conf配置檔案中開啟

開啟載入ssl配置檔案 如果沒有這一行,複制到httpd.conf檔案末尾

Include conf/extra/httpd-ssl.conf
           
第二步 自己生成證書檔案

首先切換到apache安裝目錄

Apache配置SSLApache配置SSL

生成伺服器密匙

生成簽署申請 執行這一條指令需要輸入一些資訊

Apache配置SSLApache配置SSL
Country Name (2 letter code) [AU]:CN                /*國家代碼*/
State or Province Name (full name) [Some-State]:Beijing     /*省*/
Locality Name (eg, city) []:beijing             /*地名*/
Organization Name (eg, company) [Internet Widgits Pty Ltd]:jokechat.cn /*你的域名*/
Organizational Unit Name (eg, section) []:IT Dept           /*組織機關名稱*/
Common Name (e.g. server FQDN or YOUR name) []:jokechat.cn              /*普通名稱*/
Email Address []:[email protected]                    /*郵箱位址*/

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:                              /*設定密碼*/
An optional company name []:jokechat.cn                 /*我設定公司名稱*/
           

生成CA私鑰

利用CA的私鑰産生CA的自簽署證書 這一步也需要輸入一些資訊 參照以上即可

openssl req  -new -x509 -days  -key ca.key -out ca.crt  -config ..\conf\openssl.cnf
           

為網站伺服器簽署證書 執行此指令會報錯 需要在此目錄下建立兩層目錄,兩個檔案

Apache配置SSLApache配置SSL
  • newcerts

    空目錄

  • index.txt

    建立檔案 無需填寫内容

  • serial

    檔案内容為01

現在執行則沒有問題了

現在已經生成了證書檔案

第三步 apache ssl配置檔案修改
SSLCertificateFile "D:/WWW/Apache/conf/2_jokechat.cn.crt"
/* #SSLCertificateFile "D:/WWW/Apache/conf/server-dsa.crt" */

SSLCertificateKeyFile "D:/WWW/Apache/conf/3_jokechat.cn.key"
/* ##SSLCertificateKeyFile "D:/WWW/Apache/conf/server-dsa.key"  */

SSLCertificateChainFile "D:/WWW/Apache/conf/1_root_bundle.crt"
           

然後重新啟動Apache服務就可以了

最後效果如下

Apache配置SSLApache配置SSL

如果想在本地進行測試不要忘記修改hosts

如果想在網絡上同行 有很多形式可以免費獲得認證證書

例如:CA 沃通免費SSL證書 有興趣者可以自行嘗試