安裝
關於 SVN, Trac 及 Apache 的安裝,請參考 SVN & Trac Installation 備忘,唯要讓 Apache 支援 OpenSSL,最簡單的方式,就是採用已整合 OpenSSL 的 Apache installler 版本,例如 apache_2.0.63-win32-x86-openssl-0.9.7m.msi
基本設定
取得 SSL 憑證(Certificate)
填寫憑證申請表單
D:\AppServ\Apache2\bin> openssl req -config ../conf/openssl.cnf -new -out server.csr
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
……………..++++++
……..++++++
writing new private key to 'privkey.pem'
Enter PEM pass phrase:(輸入一整個句子,比如一篇詩詞的一部份,越長越好)
Verifying - Enter PEM pass phrase:(再敲一次剛剛敲過的密碼)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [AU]:(可按 Enter 使用預設值)
State or Province Name (full name) [Some-State]:(可按 Enter 使用預設值)
Locality Name (eg, city) []:(可按 Enter 使用預設值)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:(可按 Enter 使用預設值)
Organizational Unit Name (eg, section) []:(可按 Enter 使用預設值)
Common Name (eg, YOUR name) []:svn (一定要輸入,通常是 Host + Domain name)
Email Address []:moc.revres.liam|emaNruoy#moc.revres.liam|emaNruoy(也可按 Enter 使用預設值)
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(可按 Enter 使用預設值)
An optional company name []:(可按 Enter 使用預設值)
製作公開鑰(public key)
D:\AppServ\Apache2\bin> openssl rsa -in privkey.pem -out server.key
Enter pass phrase for privkey.pem:(再敲一次先前敲過的密碼)
writing RSA key
取得憑證(9999 天後才過期)
D:\AppServ\Apache2\bin> openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 9999
Loading 'screen' into random state - done
Signature ok
subject=/CN=svn/emailAddress=moc.revres.liam|emaNruoy#moc.revres.liam|emaNruoy
Getting Private key
unable to write 'random state'
取得 DER 格式的憑證
D:\AppServ\Apache2\bin> openssl x509 -in server.crt -out server.der.crt -outform DER
將憑證放到適當的位置
把文件 server.der.crt 和 server.key 拷貝到 ..\conf\ssl
D:\AppServ\Apache2\conf> md ssl
D:\AppServ\Apache2\bin> copy server.der.crt ..\conf\ssl
D:\AppServ\Apache2\bin> copy server.key ..\conf\ssl
我們只要 server.der.crt 和 server.key 這兩個檔案,其他中間檔案(如 .rnd, privkey.pem, server.csr, server.crt)都可以刪除。
指定憑證所在路徑
打開文件 ..\conf\ssl.conf,路徑設置如下:
SSLCertificateFile conf/ssl/server.der.crt
SSLCertificateKeyFile conf/ssl/server.key
設定 SSL
打開 ssl.conf ,確保以下沒被註釋掉:
SSLRandomSeed startup builtin
SSLMutex default
將 SSLSessionCache 設置如下(確保其他行的 SSLSessionCache 設定都被註解掉了):
SSLSessionCache none
註解掉 IfDefine SSL(直接啟動 Apache 時加載 SSL ,而不用在 Apache 後面加 -D SSL):
#<IfDefine SSL>
#</IfDefine>
載入 SSL module
打開文件 ..\conf\httpd.conf ,將下面行前的註釋去掉:
LoadModule ssl_module modules/mod_ssl.so
測試
重啟 Apache 現在我們可以通過 http 和 https 兩種方式訪問 Trac 或 SVN 了。
如果我們強制要求使用 https ,最簡單的作法就是將 http 自動重定向為 https ,作法後述。
Redirect 設定
載入 rewrite module
取消 httpd.conf 中的以下模組的註釋:
LoadModule rewrite_module modules/mod_rewrite.so
利用 rewrite 重轉向
在 httpd.conf 末尾加入以下代碼,用以將 Trac 及 SVN 重定向到 HTTPS:
RewriteEngine On
# for SVN with SSL
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(/svn/.*)$ https://%{SERVER_NAME}$1 [L,R]
# for Trac with SSL
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(/trac/.*)$ https://%{SERVER_NAME}$1 [L,R]





