2014年3月20日 星期四

Appserv 2.5.9 (Apache 2.2.4 win32) + OpenSSL 0.9.8d 安裝備忘錄-轉



一、預備檔案:

在這裡說明一下,其實網路上之前的教學,大部分都是到http://hunter.campbus.com/取得Apache-openssl.zip檔案,這樣就不需要安裝,可是我現在已經無法連到該網站,只好抓Apache官方的msi安裝檔回來試試看。重要的是注意1.和2.的openssl版本要相符,可以在Apache的伺服器上找到各種版本:http://archive.apache.org/dist/httpd/binaries/win32/

二、安裝及複製Apache檔案:
執行Apache_openssl.msi,其實這就是在電腦上又多安裝了一個Apache伺服器,
不過我們只是要它其中的一些檔案而已,所以用完之後可以馬上移除掉。

預設應該安裝在C:/Program Files/Apache Software Fundation/Apache2/,
將Apache2/bin/底下的httpd.exe, ssleay32.dll, libeay32.dll複製到Appserv/Apache2.2/bin底下。

將Apache2/conf/extra/httpd-ssl.conf複製到Appserv/Apache2.2/conf/extra底下。
p.s. 記得先將Apache Service停止。

三、安裝Openssl、產生CA檔案:
將OpenSSL-0.9.8d_win32.rar解壓縮,以解壓縮至C:\Openssl為例,底下應該會有
\bin, \include, \lib, \ssl四個資料夾和一個openssl.cnf檔。

用另外抓取的openssl.cnf(一、3.)覆蓋掉原本的。

用文字編輯器打開openssl.cnf,修改以下部份:
dir = ssl
certs = $dir\\certs
crl_dir = $dir\\crl
database = $dir\\index.txt
new_certs_dir = $dir
certificate = $dir\\cacert.pem
serial = $dir\\serial
crl = $dir\\crl.pem
private_key = $dir\\privkey.pem
RANDFILE = $dir\\privkey.rnd

(注意!在編輯openssl.cnf時要注意"\\",不可以少打成"\",不然後面編輯CA檔案時,會有錯誤)

並且將x509extensions開頭的這一行註解掉。(前面加上#字號)

在C:\Openssl\下開啟新資料夾ssl,並在其中新增index.txt及serial兩個檔案,
serial用文字編輯器打開,輸入01,index.txt保持空白。

將\bin底下的檔案複製一份到C:\Openssl\底下。(這是為了避免之後路徑的困擾)

進入命令列模式,依序執行以下動作:

[1] openssl genrsa -des3 -out ssl/ca.key 1024

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

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

[4] openSSL genrsa -out ssl/server.key 1024

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

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

(在產生CA檔案的第六個步驟,會有兩個問題[y/n],都要選y.不然產生的server.crt會出錯,變成空檔案(Empty))

其中[1]會要求設定密碼,[2]和[5]會要求輸入一些憑證的基本資料。
如果有error多半是路徑錯誤,稍微檢查一下指令做修正即可。
將[6]產生的檔案(整個ssl資料夾)複製到C:/Appserv/Apache2.2/conf/底下。

四、修改httpd-ssl.conf:
打開C:\AppServ\Apache2.2\conf\extra\httpd-ssl.conf檔案,修改部份如下:
DocumentRoot 網頁根目錄,比照httpd.conf下的DocumentRoot
ServerName Server位址:443
ServerAdmin Email
ErrorLog logs/error_log
TransferLog logs/access_log
---
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key
SSLCertificateChainFile conf/ssl/ca.crt
---
將SSLMutex default註解掉,改為SSLMutex none
---
將所有沒有用雙引號包起來的絕對路徑加上雙引號,例如:
SSLSessionCache "shmcb:C:/AppServ/Apache2.2/logs/ssl_scache(512000)"
SSLCertificateFile "C:/AppServ/Apache2.2/conf/ssl/server.crt"
---
把原本的 字串刪除. 然後加上
NameVirtualHost *:443



五、修改httpd.conf:
打開C:\AppServ\Apache2.2\conf\httpd.conf檔案,修改部份如下:
把 LoadModule ssl_module modules/mod_ssl.so 的#註解拿掉
(注意!要把C:/Program...../Apache2/modules/底下的mod_ssl.so複製到C:/Appserv/Apache2.2/modules底下)
把 Include conf/extra/httpd-ssl.conf 的#註解拿掉

六、重新啟動Apache:
如果啟動過程中沒有出現錯誤,可以連https://localhost測試看看,
應該就會出現要求憑證的認證畫面了

p.s. 如果Apache啟動失敗,請檢查error.log確認是哪邊設定錯誤大致上就是這樣囉,祝各位安裝順利。

沒有留言:

張貼留言