目的: 讓apache中的網站可以用https(SSL)連線
環境: FreeBSD 6.1-R + Apache2.2


總共有以下步驟:

  1. 產生憑證
    1. 產生root CA
      1. 產生root private key
      2. 建立root require cert
      3. 利用root private key與root require建立public certification
    2. 產生server CA
      1. 產生server private key
      2. 建立server require cert
      3. 利用root public cert + server private key + server require cert來產生server public cert
  2. 設定Apache
    1. 設定private key位置
    2. 設定public cert位置
    3. 設定載入mod_ssl模組


實作:

  1. openssl genrsa -des3 -out rootCA.key 4096 (建立root private key)
  2. openssl req -new -key rootCA.key -out rootCA.req (建立root require cert)
  3. openssl x509 -days 3650 -req -sha1 -extensions v3_ca -signkey rootCA.key -in rootCA.req -out rootCA.crt (建立root public cert)
  4. 刪除rootCA.req, chmod 600 rootCA.key,以上完成root CA
  5. openssl genrsa -out server.key 4096 (建立server private key)
  6. openssl req -new -key server.key -out server.req (建立public cert request)
  7. openssl x509 -req -days 3650 -sha1 -extensions v3_req -CA rootCA.crt -CAkey rootCA.key -CAserial rootCA.srl -CAcreateserial -in server.req -out server.crt (建立server public cert)

以上就這樣完成CA憑證的建立,接下來設定Apache


  1. 設定httpd.conf
  2. 將Loadmodule mod_ssl該行的註解移除
  3. 把"Include ~/apache22/extra/httpd-ssl.conf"前的註解拿掉
  4. 修改~/apache22/extra/httpd-ssl.conf
  5. 修改default virtual server中key檔與crt檔的位置
  6. 修改default virtual server加入ScriptAlias /cgi-bin/ "/path/to/cgi-bin/"
  7. apachectl -t
  8. apachectl -k restart

這樣就完成了https的設定

文章標籤
全站熱搜
創作者介紹
創作者 lychen 的頭像
lychen

交ㄚ的blog

lychen 發表在 痞客邦 留言(0) 人氣(422)