2009年10月20日 星期二

Windows下安裝Apache + SSL

Windows下安裝Apache + SSL

前陣子剛好需要使用自發伺服器認證,由於使用的是Windows IIS,因此很簡單的幾個步驟就啟用。最近剛好有人詢問Windows下如何使用Apache Server加上OpenSSL?因此找了一些資料實地安裝了一遍,資料來源是:



http://blog.ericsk.org/archives/215



http://www.pczone.com.tw/vbb3/thread/47/96241/


這兩個網站基本上說明的已經算很清楚,但對於Apache不熟悉的人,可能還有一些問題,因此把資料匯整一下。



(1)首先下載Apache的OpenSSL版本:



http://209.61.202.80/apache/Apache_2.2.3-Openssl_0.9.8d-Win32.zip



假設你把它安裝在D:\Apache2.2\目錄下

安裝時會詢問你domain name、server name與admin email

你輸入的內容會寫到httpd.conf檔案內 (d:\apache2.2\conf\httpd.conf)



httpd.conf是啟動Apache的主要設定檔案



(2)打開httpd.conf



將LoadModule ssl_module modules/mod_ssl.so前面的#去掉

將Include conf/extra/httpd-ssl.conf前面的#去掉

將httpd.conf存檔



(3)打開D:\apache2.2\conf\extra\httpd-ssl.conf



將#SSLMutex "file:D:/Apache2.2/logs/ssl_mutex"

改成SSLMutex none



並確認:







# General setup for the virtual host

DocumentRoot "D:/Apache2.2/htdocs"

ServerName your.server.com.tw:443

ServerAdmin your@email.com

ErrorLog "D:/Apache2.2/logs/error_log"

TransferLog "D:/Apache2.2/logs/access_log"



以上your.server.com是你的機器名稱,如果沒有domain name,可以用ip來代替



這個檔案主要是Apache開啟後,需要知道SSL的設定組態



(4)繼續看httpd.conf



SSLCertificateFile "D:/Apache2.2/conf/ssl/server.crt"



SSLCertificateKeyFile "D:/Apache2.2/conf/ssl/server.key"



如果不需要瀏覽端認證,以下可以不管他:



#SSLVerifyClient require

#SSLVerifyDepth 10



如果自發認證,以下可以不管他:



#SSLCertificateChainFile "D:/Apache2.2/conf/server-ca.crt"

#SSLCACertificatePath "D:/Apache2.2/conf/ssl.crt"

#SSLCACertificateFile "D:/Apache2.2/conf/ssl.crt/ca-bundle.crt"

#SSLCARevocationPath "D:/Apache2.2/conf/ssl.crl"

#SSLCARevocationFile "D:/Apache2.2/conf/ssl.crl/ca-bundle.crl"



修改完後將httpd.conf存檔



(5)要產生SSL所需要的key的前置動作



這個動作牽涉到幾個:

(a)Apache目錄下的/bin/openssl.exe

(b)Apache目錄下的/bin/openssl.cnf (不是openssl.conf喔)



打開openssl.cnf,看看內容:



[ CA_default ]

dir= ./ssl



你先在Apache目錄下的/bin/下建立ssl目錄

也就是有了 d:\apache2.2\bin\ssl,這個目錄放置SSL檔案



(6)在 d:\apache2.2\bin\ssl下建立一個空檔案

index.txt



(7)在 d:\apache2.2\bin\ssl下建立一個檔案serial,內容就輸入01

(不要副檔名喔)



所以目前d:\apache2.2\bin\ssl有兩個檔案: index.txt與serial



在d:\apache2.2\bin\ssl下再新建一個目錄newcerts



(8)產生SSL key

以dos command進到d:\apache2.2\bin

並以下面指令產生key(中間過程會要你輸入一些組態...自己看看...應該沒問題)



d:\apache2.2\bin

openssl genrsa -des3 -out ssl/ca.key 1024



d:\apache2.2\bin

openssl req -config openssl.cnf -new -key ssl/ca.key -out ssl/ca.csr



d:\apache2.2\bin

openssl x509 -days 3650 -req -signkey ssl/ca.key -in ssl/ca.csr -out ssl/ca.crt



d:\apache2.2\bin

openSSL genrsa -out ssl/server.key 1024



d:\apache2.2\bin

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



d:\apache2.2\bin

openssl ca -config openssl.cnf -days 3650 -cert ssl/ca.crt -keyfile ssl/ca.key -in ssl/server.csr -out ssl/server.crt



檢查你的d:\apache2.2\bin\ssl下

是否有了11個檔案及一個目錄 ,將整個ssl目錄copy到d:\apache2.2\conf下



(9)現在重新開啟Apache,應該已經可以用https://來開你的SSL

如果不能的話,看看d:\apache2.2\logs\error.log是哪裡出問題

本文轉貼自樂多-【快樂很多的電腦技術筆記】 Windows下安裝Apache + SSL
http://blog.roodo.com/myroodo/archives/4219557.html


本人僅轉貼作為技術上查詢使用,若有侵權敬請告知,謝謝

沒有留言:

張貼留言