windows Apache 配置支持HTTPS的SSL證書

在設置Apache + SSL以前, 須要作:php

安裝Apache, 下載安裝Apache時請下載帶有ssl版本的Apache安裝程序.css

而且ssl須要的文件在以下的位置:java

 

    [Apache安裝目錄]/modules/ mod_ssl.soapache

    [Apache安裝目錄]/bin/ openssl.exe, libeay32.dll, ssleay32.dll, openssl.cnf安全

    [Apache安裝目錄]/conf/ openssl.cnf服務器

 

建立SSL證書(注意,我下載的是PHPStudy裏面自帶了openssl,可是bin目錄下沒有openssl.cnf,須要將conf下的openssl.cnf拷貝一份到bin目錄下,但整體原理同樣)ide

 

打開CMD,進入到Apache安裝目錄下的bin目錄下:ui

 

步驟一:spa

       執行命令:命令行

openssl genrsa 1024 >tian_server.key

       (RSA密鑰對的默認長度是1024,取值是2的整數次方,而且密鑰長度約長,安全性相對會高點)。 

      完成密鑰server.key生產完畢後進行步驟二操做。

 

步驟二:

        生產爲簽署的server.csr

       繼續在bin目錄下執行命令:

     

  openssl req -new -config openssl.cnf -key tian_server.key >tian_server.csr

       (若是不加-config .openssl.cnf參數的話,常會報Unable to load config info from .../ssl/openssl.cnf)

        以後就會要求輸入一系列的參數:

  

    Country Name (2 letter code) [AU]:CN ISO 國家代碼(只支持兩位字符)     State or Province Name (full name) [Some-State]:ZJ 所在省份     Locality Name (eg, city) []:HZ 所在城市     Organization Name (eg, company): 公司名稱     Organizational Unit Name (eg, section) []: 組織名稱     Common Name (eg, YOUR name) []: 申請證書的域名(建議和httpd.conf中serverName必須一致)     Email Address []:admin@admin.com 管理員郵箱     Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: 交換密鑰      An optional company name []:

注:Common Name建議和httpd.conf中serverName必須一致,不然有可能致使apache不能啓動(啓動 apache 時錯誤提示爲:server RSA certificate CommonName (CN) `Kedou' does NOT match server name!? )    

    完成簽署的server.csr配置。

 

步驟三:

       簽署服務器證書文件 server.crt

       在 bin/目錄下執行命令:

      

 
openssl req -x509 -days 5000 -config openssl.cnf -key tian_server.key -in tian_server.csr >tian_server.crt

       說明:這是用步驟 1,2 的的密鑰和證書請求生成證書 server.crt,-days 參數 指明證書有效期,單位爲天,x509 表示生成的爲 X.509 證書。

步驟四:

       在bin 目錄下,找到tian_server.crt、tian_server.csr、tian_server.key三個文件,將此三個文件剪切到Apache的conf目錄下。

步驟五:

       配置 httpd.conf. 在Apache的conf\extra目錄下的 httpd_ssl.conf 文件是關於 ssl 的配置,是httpd.conf的一 部分。

       在 httpd.conf 中添加下列兩行:

    

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

     

 

步驟六:

  (注意:相同部分被省略掉)

在conf\extra目錄下,編輯 httpd_ssl.conf
Listen 443 SSLPassPhraseDialog  builtin SSLSessionCache  "dbm:D:/Program/Apache Software/Apache2.2.17/logs/ssl_scache" #SSLSessionCache   "shmcb:D:/Program/Apache Software/Apache2.2.17/logs/ssl_scache(512000)" (以上2種請自行監測,若有一種致使服務器啓動不了,就換成另外一種) SSLSessionCacheTimeout  300         <VirtualHost _default_:443> # General setup for the virtual host   DocumentRoot "D:/PHPStudy/WWW/phpSSL"   ServerName  phpssl.com:443   ErrorLog "D:/PHPStudy/Apache/logs/no-robots_error.log.txt"   TransferLog "D:/PHPStudy/Apache/logs/no-robots_access.log.txt"      SSLCertificateFile "D:/PHPStudy/Apache/conf/tian_server.crt"   SSLCertificateKeyFile "D:/PHPStudy/Apache/conf/tian_server.key"      CustomLog "D:/PHPStudy/Apache/logs/ssl_request.log" \           "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

 

以上最容易出問題的地方是http_ssl.conf中的日誌等路徑問題,建議按照物理路徑進行設置


步驟八:

調試運行Apache,對於Apache。若是是集成板的如xampp,wampserver,或者phpstudy啓動Apache Server,可能咱們不知道咱們的服務器出現了什麼問題,建議查看 Apache/logs下的日誌,在此基礎上,配合Cmd命令行在bin目錄下運行httpd命令,若是不報錯,說明服務器運行沒問題,不然更具提示修改問題

 

 

步驟九:

多虛擬機https配置

<VirtualHost *:80>
ServerAdmin hao2005128@126.com
DocumentRoot "D:/www/Cema"
ServerName cema.zhu20.me


<Directory "D:/www/Cema">
Options -Indexes +FollowSymlinks
AllowOverride All
</Directory>

</VirtualHost>
<VirtualHost *:443>
ServerAdmin hao2005128@126.com
DocumentRoot "D:/www/Cema"
ServerName cema.zhu20.me
SSLEngine on
SSLCertificateFile "D:/wap/Apache24/bin/tian_server.crt"
SSLCertificateKeyFile "D:/wap/Apache24/bin/tian_server.key"
<Directory "D:/www/Cema">
Options -Indexes +FollowSymlinks
AllowOverride All
</Directory>

</VirtualHost>

相關文章
相關標籤/搜索