windows Apache 環境下配置支持HTTPS的SSL證書


windows Apache 環境下配置支持HTTPS的SSL證書

1.准備工作

1)在設置Apache + SSL之前, 需要做:

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

並且ssl需要的文件在如下的位置:

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

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

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

創建SSL證書(注意,有的集成環境里面自帶了openssl,但是bin目錄下沒有openssl.cnf,需要將conf下的openssl.cnf拷貝一份到bin目錄下,但總體原理一樣)

2)在windows環境下需先設置Openssl環境變量:

執行命令  set OPENSSL_CONF=..\conf\openssl.cnf

 

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

步驟一:執行命令 openssl genrsa 1024 >server.key

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

 

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

 

步驟二:生產為簽署的server.csr,繼續在bin目錄下執行命令:

openssl req -new -config openssl.cnf -key server.key >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): yiban公司名稱

    Organizational Unit Name (eg, section) []:yiban 組織名稱

    Common Name (eg, YOUR name) []: localhost:80申請證書的域名(建議和httpd.conf中serverName必須一致)

    Email Address []:admin@admin.com 管理員郵箱

    Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: 1234交換密鑰

An optional company name []:CD

注: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 server.key -in server.csr >server.crt

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

步驟四:

在bin 目錄下,找到server.crt、server.csr、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:c:/Apache24/logs/ssl_scache"

#SSLSessionCache  "shmcb:c:/Apache24/logs/ssl_scache(512000)"

(以上2種請自行監測,如有一種導致服務器啟動不了,就換成另一種)

SSLSessionCacheTimeout  300

<VirtualHost www.my.com:443>

    #DocumentRoot "D:/wamp/bin/apache/apache2.4.9/htdocs"

    DocumentRoot "C:/wamp/www/hxq"

    ServerName  www.my.com:443

    ServerAlias my.com:443

    ServerAdmin webmaster@chinancce.com

    DirectoryIndex index.html index.htm index.php default.php app.php u.php

    ErrorLog logs/example_error.log

    CustomLog logs/example_access.log \

    "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

    SSLEngine On

    SSLCertificateFile "C:/wamp/bin/apache/apache2.4.9/conf/server.crt"

    SSLCertificateKeyFile "C:/wamp/bin/apache/apache2.4.9/conf/server.key"

    #SSLCertificateChainFile "C:/upupw/Apache2/conf/1_root_bundle.crt"

<FilesMatch "\.(shtml|phtml|php)$">

    SSLOptions +StdEnvVars

</FilesMatch>

    BrowserMatch "MSIE [2-5]" \

    nokeepalive ssl-unclean-shutdown \

    downgrade-1.0 force-response-1.0

<Directory "C:/wamp/www/hxq">

    Options FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all

</Directory>

</VirtualHost>

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

步驟七:

調試運行Apache,對於Apache。如果是集成環境如xampp,wampserver,或者phpstudy啟動Apache Server,可能我們不知道我們的服務器出現了什么問題,建議查看 Apache/logs下的日志,在此基礎上,配合cmd命令行在bin目錄下運行httpd命令,如果不報錯,說明服務器運行沒問題,否則根據提示再做修改

2.測試運行

 重啟apahce服務,訪問https://www.my.com/,完工!

===========出現錯誤匯集==========

 

1、"Syntax error on line 80 of c:/apache/conf/extra/httpd-ssl.conf:ErrorLog takes one argument,The filename of the error log"或者"Syntax error on line 99 of c:/apache/conf/extra/httpd-ssl.conf:SSLCertificateFile takes one argument,SSL Server Certificate file ('/path/to/file' -PEM or DER encoded)"

解決方法:文件路徑加雙引號

2、"Syntax error on line 76 of C:/apache/conf/extra/httpd-ssl.conf:SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?)."

解決辦法:

打開httpd.conf,

找到LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

把前面的注釋去掉。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM