Apache+mod_ssl

戻る
02/10/15 更新
01/08/06 初版

Apache+mod_ssl の導入

前提システム:TurboLinux Server 6.1

 導入から起動までの手順

  1.ソースの準備
  2.OpenSSLのインストール
  3.Apacheのソースを準備
  4.mod_sslのコンフィグレーション(Apacheへのpatch)
  5.Apache+mod_sslのコンフィグレーションとmake
  6.SSL用の証明書の作成
  7.Apache+mod_sslのインストール
  8.httpd.confの修正
  9.Apache+mod_sslの起動
  10.Apache+mod_sslの動作を確認

 追補1.SSL用の証明書の更新
 追補2.VeriSignでSSLのサーバー証明書をとる


 1.必要なソースを準備する。

   それぞれの最新版をゲットする。
   OpenSSLに関してはrpmパッケージでも可。


  OpenSSLのソース

   01/08/06 現在の最新版は OpenSSL 0.9.6b です。

   http://www.infoscience.co.jp/technical/openssl/ <-- 日本語サイト
   http://www.openssl.org/ <-- 本家 最新版はここ
   TurboLinux Server6.1 update <-- TLS6.1用 rpmパッケージ

  Apacheのソース

   01/08/06 現在の最新版(安定版)は Apache 1.3.20 です。

   http://www.apache.or.jp/ <-- 日本語サイト
   http://japache.infoscience.co.jp/ <-- 日本語サイト
   http://httpd.apache.org/ <-- 本家 最新版はここ

  mod_sslのソース

   01/08/06 現在の最新版は Apache 1.3.20用の mod_ssl 2.8.4-1.3.20 です。

   http://www.modssl.org/ <-- 本家 最新版はここ


 2.OpenSSLをインストールする。(導入済みの場合は次へ)

 ex.) $ tar zxfv openssl-x.x.x.tar.gz
    $ cd openssl-x.x.x
    $ ./config shared
         ^^^^^^ <-- openssh等で共有lib を使用する場合に必要
    $ make
    $ make test
    $ su
    # make install <-- デフォルトでは /usr/local/ssl にインストールされる

      注) rpmでインストールしている場合、開発環境(openssl-devel-x.x.x-x)がインストール
        されているかを確認する。されていなければする。
        rpmでOpenSSLをインストールした場合若干注意が必要。


 3.Apacheのソースを展開

  Apacheのソースを展開する。

 ex.) $ tar zxfv apache_1.3.20.tar.gz


 4.mod_sslのコンフィグレーション(Apacheへのpatch)

  mod_sslのソースを展開する。

 ex.) $ tar zxfv mod_ssl-2.8.4-1.3.20.tar.gz

  Apacheへの組み込み

 ex.) $ cd mod_ssl-2.8.4-1.3.20
    $ ./configure --with-apache=../apache_1.3.20 \ <-- Apacheのソースディレクトリー
    > --prefix=/usr/local/apache_mssl \ <-- Apacheをインストールするディレクトリー
    > --enable-shared=ssl \
    > --with-ssl=/usr/local/ssl <-- OpenSSLのディレクトリー


   注)OpenSSLをrpmでインストールした場合
 ex.) $ cd mod_ssl-2.8.4-1.3.20
    $ ./configure --with-apache=../apache_1.3.20 \ <-- Apacheのソースディレクトリー
    > --prefix=/usr/local/apache_mssl \ <-- Apacheをインストールするディレクトリー
    > --enable-shared=ssl
     * '--with-ssl='は指定しない

 5.Apache+mod_sslのコンフィグレーションとmake

  configureの実行

 ex.) $ cd apache_1.3.20
    $ ./configure --enable-module=all --enable-shared=max \
    > --prefix=/usr/local/apache_mssl
         ^^^^^^^^^^^^^^^^^^^^^^ <-- インストールするディレクトリー

  configureの実行(OpenSSLをrpmでインストールした場)

 ex.) $ cd apache_1.3.20
    $ SSL_BASE=/usr  <-- これがみそ
    $ ./configure --enable-module=all --enable-shared=max \
    > --prefix=/usr/local/apache_mssl
         ^^^^^^^^^^^^^^^^^^^^^^ <-- インストールするディレクトリー

  Apache+mod_sslをmakeします。

 ex.) $ make


 6.SSL用の証明書の作成

  Apache+mod_sslをインストールする前にSSL用の証明書を作成します。

 ex.) $ su
    # make certificate
    make[1]: Entering directory `/home/hoge/src/apache_1.3.20/src'
    SSL Certificate Generation Utility (mkcert.sh)
    Copyright (c) 1998-2000 Ralf S. Engelschall, All Rights Reserved.

    Generating test certificate signed by Snake Oil CA [TEST]
    WARNING: Do not use this for real-life/production systems
    ______________________________________________________________________

    STEP 0: Decide the signature algorithm used for certificate
    The generated X.509 CA certificate can contain either
    RSA or DSA based ingredients. Select the one you want to use.
    Signature Algorithm ((R)SA or (D)SA) [R]: <-- リターン
    ______________________________________________________________________

    STEP 1: Generating RSA private key (1024 bit) [server.key]
    50471 semi-random bytes loaded
    Generating RSA private key, 1024 bit long modulus
    ...++++++
    ..++++++
    e is 65537 (0x10001)
    ______________________________________________________________________

    STEP 2: Generating X.509 certificate signing request [server.csr]
    Using configuration from .mkcert.cfg
    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.
    -----
    1. Country Name             (2 letter code) [XY]:JP <-- 国
    2. State or Province Name   (full name)     [Snake Desert]:Aomori <-- 県
    3. Locality Name            (eg, city)      [Snake Town]:Hachinohe <-- 市
    4. Organization Name        (eg, company)   [Snake Oil, Ltd]:hoge fuga inc. <-- 組織 *1
    5. Organizational Unit Name (eg, section)   [Webserver Team]:webmaster
    6. Common Name              (eg, FQDN)      [www.snakeoil.dom]:www.hoge.hogefuga.net <-- サーバー名(FQDN) *2
    7. Email Address            (eg, name@FQDN) [www@snakeoil.dom]:webmaster@hoge.hogefuga.net <-- メールアドレス
    8. Certificate Validity     (days)          [365]:

        *1 ドメインのレジストラーに登録されている名称
        *2 使用する Webサーバーの FQDN
    ______________________________________________________________________
   
    STEP 3: Generating X.509 certificate signed by Snake Oil CA [server.crt]
    Certificate Version (1 or 3) [3]: <-- リターン
    Signature ok
    subject=/C=JP/ST=Aomori/L=Hachinohe/O=hoge fuga inc./OU=webmaster/CN=www.hoge.hogefuga.net/Email=webmaster@hoge.hogefuga.net
    Getting CA Private Key
    Verify: matching certificate & key modulus
     read RSA key
    Verify: matching certificate signature
    ../conf/ssl.crt/server.crt: OK
    ______________________________________________________________________

    STEP 4: Enrypting RSA private key with a pass phrase for security [server.key]
    The contents of the server.key file (the generated private key) has to be
    kept secret. So we strongly recommend you to encrypt the server.key file
    with a Triple-DES cipher and a Pass Phrase.
    Encrypt the private key now? [Y/n]: <-- リターン
    Fine, you're using an encrypted RSA private key.
    read RSA key
    writing RSA key
    Enter PEM pass phrase: <-- パスフレーズ
    Verifying password - Enter PEM pass phrase: <-- パスフレーズをもう一度
    Fine, you're using an encrypted RSA private key.
    ______________________________________________________________________
   
    RESULT: Server Certification Files
   
    o  conf/ssl.key/server.key
       The PEM-encoded RSA private key file which you configure
       with the 'SSLCertificateKeyFile' directive (automatically done
       when you install via APACI). KEEP THIS FILE PRIVATE!

    o  conf/ssl.crt/server.crt
       The PEM-encoded X.509 certificate file which you configure
       with the 'SSLCertificateFile' directive (automatically done
       when you install via APACI).
   
    o  conf/ssl.csr/server.csr
       The PEM-encoded X.509 certificate signing request file which
       you can send to an official Certificate Authority (CA) in order
       to request a real server certificate (signed by this CA instead
       of our demonstration-only Snake Oil CA) which later can replace
       the conf/ssl.crt/server.crt file.

    WARNING: Do not use this for real-life/production systems

    make[1]: Leaving directory `/home/hoge/src/apache_1.3.20/src'
      


 7.Apache+mod_sslのインストール

  SSL用の証明書の作成を行ったらApache+mod_sslをインストールします。

 ex.) # make install


 8.httpd.confの修正

  Apache+mod_sslの動作設定を行います。
   (SSL用の設定を抜粋)


 ex.) # cd /usr/local/apache_mssl
    # cd conf
    # vi httpd.conf


    *接続ポートの設定

    <IfDefine SSL>
     Listen 80  <-- 通常の接続 port 80
     Listen 443 <-- SSLでの接続 port 443
    </IfDefine>

   *サーバー名の設定

    ServerName www.hoge.hogefuga.net


   *SSLヴァーチャルホストの設定


    <IfDefine SSL>
     <VirtualHost _default_:443> <-- 接続ポートの設定:前項の接続ポートの値
      DocumentRoot "/usr/local/apache_mssl/htdocs_ssl"
                  ^-- SSL接続時のドキュメントディレクトリー
      ServerName www.hoge.hogefuga.net <-- サーバー名
            :
            :
            :
     </VirtualHost>
    </IfDefine SSL>



 9.Apache+mod_sslの起動


   Apache+mod_sslは起動時に「SSL用の証明書の作成」で設定した
   パスフレーズを入力しなければいけない。
   自動起動などを行う場合はパスフレーズを解除しておく。

    パスフレーズの解除

 ex.) # cd /usr/local/apache_mssl/conf/ssl.key
    # cp -p server.key server.key.org
    # openssl rsa -in server.key.org -out server.key
    read RSA key
    Enter PEM pass phrase: <-- パスフレーズを入力
    writing RSA key


   通常モードでの起動
 ex.) # /usr/local/apache_mssl/apachectl start


   SSLモードでの起動
 ex.) # /usr/local/apache_mssl/apachectl startssl
                     ^^^^^^^^
    * sslstart/start-SSL でも可

 10.Apache+mod_sslの動作を確認

   通常モード
 ex.) http://www.hoge.hoge.net/


   SSLモード
   "/usr/local/apache_mssl/htdocs_ssl"に予めダミーの index.html を作成しておく
 ex.) https://www.hoge.hoge.net/
    ^^^^^
    SSLのダイアログが表示されればOK




 追補1. SSL用の証明書の更新



 追補2. VeriSignでSSLのサーバー証明書をとる