トップページ > Apache関連 > Apache2 の SSL 設定 【Solaris10】
カテゴリー
オラクルエンジニア通信
サポートページ
マニュアルページ
ソフトウェアダウンロード
中古UNIXマシン購入
blogs.sun.com
お勧めサイト
プライベートリンク

Apache2 の SSL 設定 【Solaris10】

Solaris 10 11/06 (U3)を用いて Apache2+SSL の設定をしてみます。
 
Solaris 10 11/06 (U3)を用いて Apache2+SSL の設定をしてみます。
(当然ですが、この例で使用する証明書は自己署名ですのでテスト運用や特定の組織内の運用には使えますが、外部向けのサービスには向いていません。)

Apache 2.0.x からは mod_ssl モジュールがデフォルトでインストールされています。mod_sslがインストールされていると、/etc/apache2/ssl.conf という設定ファイルが生成されます。このファイルは、デフォルト状態でも必要な設定がひととおり行われているため、特に変更する必要はありません。なお、 デフォルトでは、
サーバ証明書は /etc/apache2/ssl.crt/server.crt に、
サーバ用の秘密鍵は /etc/apache2/ssl.key/server.key になっています。

デフォルトの設定ファイル群を確認してみます。

bash-3.00# pwd
/etc/apache2

bash-3.00# ls
highperformance-std.conf  httpd.conf-example        ssl-std.conf
highperformance.conf      magic                     ssl.conf
httpd-std.conf            mime.types

■ apache2 サービスの有効化

まずは SSL を有効にせず、 apache2 サービスを有効にします。

bash-3.00# pwd
/etc/apache2
bash-3.00# cp  httpd.conf-example  httpd.conf

以下のように ServerName だけ適当に編集します。

bash-3.00# vi  httpd.conf
...
ServerName sol10pc.example.com

svcadm コマンドで apache2 サービスを有効にします。

bash-3.00# svcadm  enable  apache2
bash-3.00# svcs  apache2
STATE          STIME    FMRI
online         18:26:25 svc:/network/http:apache2

当然、この設定では SSL は有効になっていません。

■ SSL の有効化

httpd.conf に以下のエントリがあることを確認します。
----------------------------------
<IfModule mod_ssl.c>
    Include /etc/apache2/ssl.conf
</IfModule>
----------------------------------
SSLの詳細な設定は /etc/apache2/ssl.conf ファイルで行います。
/etc/apache ディレクトリに移動し、ssl.conf ファイルを開きます。

bash-3.00# cd /etc/apache2
bash-3.00# vi ssl.conf
--------------------------------------
...
<VirtualHost 192.168.1.1:443>   <--- _default_ をWebサーバーのIPアドレスに置き換える
...
SSLCertificateFile /etc/apache2/ssl.crt/server.crt   
...
SSLCertificateKeyFile /etc/apache2/ssl.key/server.key
...
-------------------------------------------
上記のように一部を修正し、SSLCertificateFileとSSLCertificateKeyFileの設定値を確認します。
SSLCertificateFileにはサーバ証明書ファイル、SSLCertificateKeyFileにはサーバ用秘密鍵のファイルが指定されて います。

/etc/apache2 ディレクトリで、今確認したサーバ証明書とサーバ用の秘密鍵を格納するためのディレクトリを作成します。

bash-3.00# cd  /etc/apache2
bash-3.00# mkdir  ssl.crt
bash-3.00# mkdir  ssl.key
bash-3.00# ls -F
highperformance-std.conf   magic                      ssl.crt/
highperformance.conf       mime.types                 ssl.key/
httpd-std.conf             ssl-std.conf
httpd.conf-example         ssl.conf

証明書や鍵の作成などの作業用のディレクトリを作り移動します。

bash-3.00# mkdir  tmp
bash-3.00# ls  -F
highperformance-std.conf   magic                      ssl.crt/
highperformance.conf       mime.types                 ssl.key/
httpd-std.conf             ssl-std.conf               tmp/
httpd.conf-example         ssl.conf
bash-3.00# cd  tmp

openssl コマンドを使用するため以下のようにパスを通しておきます。

bash-3.00# PATH=$PATH:/usr/sfw/bin
bash-3.00# export PATH

SSLを使用するには、まずCAの秘密鍵を作成します。

bash-3.00# openssl  genrsa  -rand  /var/adm/messages  -out ca.key  1024
271074 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
.++++++
...............++++++
e is 65537 (0x10001)

-rand オプションは、ランダムデータの基となるファイルを適当に指定します。この例では /var/adm/messages ファイルを使っています。これにより、RSA 方式で 1024bit の秘密鍵(ca.key)が作成されます。

 次に、ca.key から CA 証明書の署名要求(CSR)を作成します。ここで対話的に入力した国名などの情報は、発行される証明書に表示されます。

bash-3.00# openssl  req  -new  -key  ca.key  -out ca.csr
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) [US]:JP
State or Province Name (full name) [Some-State]:Tokyo
Locality Name (eg, city) []:Shinagawa
Organization Name (eg, company) [Unconfigured OpenSSL Installation]:Example KK
Organizational Unit Name (eg, section) []:Test Dept
Common Name (eg, YOUR name) []:Test User
Email Address []:testuser@example.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

続いて、CA 証明書に署名して発行します。ここでは指定していませんが、-daysオプションにより、証明書の有効期限を設定することも可能です。例えば、「- days 365」とすると1年間有効の証明書が発行されます。

bash-3.00# ls
ca.csr  ca.key
bash-3.00# openssl  x509  -req  -in  ca.csr  -signkey  ca.key  -out  ca.crt
Signature ok
subject=/C=JP/ST=Tokyo/L=Shinagawa/O=Example KK/OU=Test Dept/CN=Test User/emailAddress=testuser@example.com
Getting Private key

以降はサーバ用の証明書を作成する作業になります。最初に、サーバ用の秘密鍵を作成します。

bash-3.00# openssl  genrsa  -rand  /var/adm/messages  -out  server.key  1024
271074 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
...........++++++
.................................++++++
e is 65537 (0x10001)

サーバ用の秘密鍵からサーバ証明書の CSR を作成します。CA 証明書の CSR と同様に、各種情報を対話的に入力します。今回の Common Name にはサーバのホスト名を入力します。

bash-3.00# openssl  req  -new  -key  server.key  -out  server.csr
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) [US]:JP
State or Province Name (full name) [Some-State]:Tokyo
Locality Name (eg, city) []:Shinagawa
Organization Name (eg, company) [Unconfigured OpenSSL Installation]:Example KK
Organizational Unit Name (eg, section) []:Test Dept
Common Name (eg, YOUR name) []:sol10pc.example.com
Email Address []:webmaster@example.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

サーバ用の証明書に署名して発行する前に、認証局が使用するシリアルナンバーのファイルを作成しておく必要があります。

bash-3.00# echo  01  >  ca.srl

準備ができたので、証明書を発行します。ここでは、「-days 365」として1年間有効の証明書を発行しています。

bash-3.00# openssl  x509  -req  -days  365  -CA  ca.crt  -CAkey  ca.key  -CAserial  ca.srl  -in  server.csr  -out server.crt
Signature ok
subject=/C=JP/ST=Tokyo/L=Shinagawa/O=Example KK/OU=Test Dept/CN=sol10pc.example.com/emailAddress=webmaster@example.com
Getting CA Private Key

作成したserver.crtとserver.keyを以下のようにコピーする。

bash-3.00# cp  server.crt  /etc/apache2/ssl.crt
bash-3.00# cp  server.key  /etc/apache2/ssl.key


これで apache2 サービスで SSL を利用する準備が整いましたが、以下のように apache2 サービスの httpd/ssl プロパティが false に設定されているため、通常の起動では apachectl コマンドで startssl 引数が使用されません。
(参照:/lib/svc/method/http-apache2 ファイル)

bash-3.00# svcprop  -p  httpd/ssl apache2
false

以下のように httpd/ssl プロパティを true に設定して apache2 サービスを再起動します。

bash-3.00# svccfg  -s  apache2
svc:/network/http:apache2> setprop  httpd/ssl  =  boolean:  true
svc:/network/http:apache2> end

bash-3.00# svcadm  refresh  apache2
bash-3.00# svcprop  -p  httpd/ssl  apache2
true
bash-3.00# svcadm  -v  restart  apache2
Action restart set for svc:/network/http:apache2.

以下のようにプロセスを見ても SSL が有効になっているのがわかります。

bash-3.00# ps  -ef  |  grep  httpd
webservd  1961  1959   0 18:26:26 ?           0:00 /usr/apache2/bin/httpd -k start -DSSL
webservd  1962  1959   0 18:26:26 ?           0:00 /usr/apache2/bin/httpd -k start -DSSL
webservd  1963  1959   0 18:26:26 ?           0:00 /usr/apache2/bin/httpd -k start -DSSL
webservd  1967  1959   0 18:27:23 ?           0:00 /usr/apache2/bin/httpd -k start -DSSL
    root  1959     1   0 18:26:25 ?           0:01 /usr/apache2/bin/httpd -k start -DSSL
webservd  1964  1959   0 18:26:26 ?           0:00 /usr/apache2/bin/httpd -k start -DSSL
webservd  1960  1959   0 18:26:26 ?           0:00 /usr/apache2/bin/httpd -k start -DSSL

オラクルユニバーシティSolaris系技術トレーニング一覧

Solarisお勧め書籍

Solaris 11.2 システムハンドブック
Oracle Solaris 11 試験対策本(OCA)