在 How to get a free HTTPS web certification authority by StartSSL.com 一文中,我申請了 A.hoamon.info 的公錀簽核,也正確地跑在 https 上,在使用瀏覽器觀看時,完全沒有問題。然而在 hg 軟體上,卻會發生 SSL: Server certificate verify failed. 的錯誤訊息,從 Mercurial on Windows vs Linux, spot the problem 一文中,作者解釋是 Windows 的 ssl 版本太舊的原因,但照他的解決方案處理,我的 hg 軟體卻是報 URLError. 錯誤。
後來在檢查 apache.conf 時發現,這台機器有三個 https 站台,一個是用 A.hoamn.info 的公錀,另外兩個 B, C 站台卻都是用 whatever.hoamon.info 的公錀。而 B, C 站台的設定檔寫得比 A.hoamon.info 站台還前面。所以試著調動 A.hoamon.info 到 B, C 站台設定的前面,結果 hg 軟體就正常了。
問題是解決了,但我反而混亂了。印象中, https 協定中,公錀是在 IP 層(或表現層,我不確定)就發送至使用者的瀏覽器,既然沒到應用層,則網頁伺服器就不知道該拿那一個虛擬站台的公錀給使用者,於是它總是拿第一個看到的公錀(也就是寫在最前面的),所以這篇教學文章,才會寫到:「…一個 Apache ,也只能架一個 SSL 站,用一個站名。除非妳跑很多份 Apache ,各自跑在不 同的 IP 或不同的 TCP 埠上,才能在同一臺伺服 器上,跑好幾個 SSL 站。」
實際上,在 Windows XP 的 IE, Safari 上觀看 A, B, C 三個站台,也的確都是拿到 A.hoamon.info 的公錀。但在 Chrome, Firefox 上,卻是看到 A 用 A.hoamon.info ,但 B, C 用的是 whatever.hoamon.info 的公錀。

- 註冊帳戶
- 驗證網址
- 公錀簽核
# openssl genrsa -des3 -out exmple.com.key 4096
Generating RSA private key, 4096 bit long modulus
................................................................................................................................................................++
...............................................++
e is 65537 (0x10001)
Enter pass phrase for exmple.com.key:
Verifying - Enter pass phrase for exmple.com.key:
從新增的私錀中,產生一個憑證請求檔,並在請求檔中,寫入「目標網址」(也就是你剛驗證過的那個網址)的所屬資料,如:所在地、單位名稱、負責人信箱等:
# openssl req -new -key exmple.com.key -out exmple.com.csr
Enter pass phrase for exmple.com.key:
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]:{{TW}}
State or Province Name (full name) [Some-State]:{{Taichung}}
Locality Name (eg, city) []:{{Taichung}}
Organization Name (eg, company) [Internet Widgits Pty Ltd]:{{EXAMPLE-Company}}
Organizational Unit Name (eg, section) []:{{EXAMPLE-Company}}
Common Name (eg, YOUR name) []:{{EXAMPLE Company}}
Email Address []:{{master@exmple.com}}
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
然後在 Apache 設定檔中設定如下:
SSLEngine on重新啟動 Apache 時,它會問你私錀密碼為何? 這個動作在管理員面前發生是沒有問題的,但在系統自動重開機時,會造成困惱,所以我們可移除私錀的加密,指令如下:
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
SSLCertificateFile /etc/apache2/example.com.crt
SSLCertificateKeyFile /etc/apache2/example.com.key
SSLCertificateChainFile /etc/apache2/sub.class1.server.ca.pem
SSLCACertificateFile /etc/apache2/ca.pem
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
# openssl rsa -in exmple.com.key -out exmple.com.key.no_password
exmple.com.key.no_password 這個私錀檔就是沒加密的,將它寫入 apache 設定檔即可。
照著這位仁兄的筆記: http://blog.roodo.com/myroodo/archives/4219557.html ,就是會在最後一個指令
> openssl ca -config openssl.cnf -days 3650 -cert ssl/ca.crt -keyfile ssl/ca.key -in ssl/server.csr -out ssl/server.crt
出現
I am unable to access the ssl
ewcerts directory
ssl
ewcerts: Invalid argument
查了相當多的地方,也找不出原因。後來想想,這不過是個憑證,它是一種資料,所以它應該與平台無關,且之前我在 Linux 上作了那麼多的憑證,也沒遇過機器重灌,憑證得重作的現象,所以它應與當時製作的平台也無關,索性在 Ubuntu 上打了三個指令,作出憑證,再送到 Windows 去用。
您猜猜,這麼著了?
It's Work~
和 Fedora 的設定方式稍有不同。
1. 產生認證檔案
sudo mkdir /etc/apache2/ssl
sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
2. 修改設定檔案 /etc/apache2/sites-available/ssl
NameVirtualHost *:443
<virtualhost *:443>
ServerAdmin webmaster@localhost
...
...
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
</virtualhost>
3. 重新啟動 Apache 伺服器
sudo /etc/init.d/apache2 restart




























