服務器配置openssl支持 https 訪問

 

一、Windows + apache 下,  軟件是xampp

  說明:部分參考(http://blog.sina.com.cn/s/blog_5d7dbbdd0101042n.html

  首先要載入 mod_ssl 。

 

  1. 將證書生成的配置文件(http://tud.at/programm/openssl.cnf) 複製到 apache/bin/openssl.cnf

  2. cmd進入apache/bin目錄(必須是 openssl.exe 所在目錄)。  使用命令生成

    openssl req -config ./openssl.cnf -new-out server.csr  

   ## 逐次填寫信息

    openssl rsa -in privkey.pem -out server.key   

    openssl x509 -in server.csr -out server.crt -req -signkey server.key  

     openssl req -x509 -days 730 -key server.key -in server.csr > server.crt 

  或,版本較新可以使用這個
     set openssl_conf=./openssl.cnf 
     openssl genrsa 4096 -des3 > server.key 
     openssl req -new -key server.key > server.csr 
  
 
  
set openssl_conf=./openssl.cnf
   openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr
   ## 加 -nodes 的作用: key 將不會用DES 加密字符加密, ————這在windows上可能非常重要,win上可能會有一個啓動錯誤 SSLPassPhraseDialog  builtin 。
  
 ## 逐次填寫內容. 設密碼。
    

  3.這當前進入的目錄(***apache/bin)生成了幾個文件, 將 server.key, server.crt 複製到

    apache/conf/ssl.crt/example.crt

    apache/conf/ssl.key/example.key

    ##  重命名,是在有多個虛擬主機時名字不重複

 

  4. 依照示例配置 http-ssl.conf.

    <VirtualHost  *:443>

                 SSLEngine on
      ServerName example.com:443

                 DocumentRoot "E:/www/example.com"

      #ServerAdmin [email protected]

      #ErrorLog "logs/error.log"

      SSLCertificateFile "E:/mySoft/xampp/apache/conf/ssl.crt/example.crt"
      SSLCertificateKeyFile "E:/mySoft/xampp/apache/conf/ssl.key/example.key"


      <IfModule log_config_module>
        CustomLog "logs/access.log" combined
      </IfModule>


      <Files ~"\.(cgi|shtml|phtml|php|htm|html?)$>
        SSLOptions +StdEnvVars
      </Files>


    </VirtualHost>

    其他參數和80端口一樣就行。Files匹配 參數見說明 http://httpd.apache.org/docs/2.0/mod/mod_ssl.html#ssloptions

  可能遇到的錯誤: 

  [warn] Init: (23.234.16.94:443) You configured HTTP(80) on the standard HTTPS(443) port!

  解決:  SSLEngine on

   自動跳轉到第一個vhost:

    <Virtualhost *:443> 之前加個 NameVirtualHost *:443   

 

  題外話:

    其實自己生成的證書沒什麼意義,僅供本地開發。 當然,有很多賣證書的網站,使用上面手動生成的 csr 文本內容生成 crt(sha1或sha2加密在這一步設定)。

        VeriSign的過於昂貴,最便宜的要 2000一年。我申請了 startSsl.com 的免費版,當然它的基礎付費版也才 $49一年,坑爹的是如果你要刪除這個域名,需要付$24美元。最後

      我搞了個 Comodo.com 的, $64.99/年,可以試用90天,很好。

  

  另外一個問題是, 如果你的運行系統是 windows xp sp2 以下, 並不支持sha2加密的,可以使用sha1加密,或者下載補丁 (官方補丁下載)

 

Linux記錄暫無, 其實基本一樣。

 

轉載於:https://www.cnblogs.com/antarctican/p/4037945.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章