naobe @ ウィキ
Apatche 2.2.3
最終更新:
Bot(ページ名リンク)
-
view
環境
MPM
使用しているMPMの確認
$ httpd -l Compiled in modules: core.c prefork.c http_core.c mod_so.c
上記では、prefork(スレッドを使わない。前もってプロセスを起動)を使用している。
Tomcatとの連携
CentOS 5.5では、httpd.confに以下の設定がある
ServerRoot "/etc/httpd" Include conf.d/*.conf
/etc/httpd/conf.d/proxy_ajp.confに以下の設定があるのでコメントを除く。
ProxyPass /tomcat/ ajp://localhost:8009/ #ProxyPass /examples/ ajp://localhost:8009/jsp-examples/
上記では、ドキュメントルート/tomcat下のURLが全てTomcatに転送される。
/etc/init.d/httpd restartを実効
http://サーバ/tomcat/で、Tomcatの初期画面を表示する。
SSL
tomcatと連携する場合でも、apacheでSSLの設定をしておけばよいようだ。apach, tomcat間は復号化した伝文をやり取りするということ?
mod_sslインストール確認
CentOS5.5には既にmod_sslがインストールされている。
$ rpm -ql mod_ssl-2.2.3-45.el5.centos.1 /etc/httpd/conf.d/ssl.conf /usr/lib/httpd/modules/mod_ssl.so /var/cache/mod_ssl /var/cache/mod_ssl/scache.dir /var/cache/mod_ssl/scache.pag /var/cache/mod_ssl/scache.sem
秘密鍵作成
server.keyが秘密鍵になる。
# openssl genrsa -des3 1024 > server.key
| オプション | 説明 |
|---|---|
| -des3 | 秘密鍵をトリプルDESで作成する |
| 1024 | 秘密鍵のビットサイズ |
公開鍵、組織情報作成
server.csrは公開鍵と、証明局がデジタル証明書を作成するときのもととなる組織の情報を含む。
# openssl req -new -key server.key > server.csr Enter pass phrase for server.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) [GB]:JP State or Province Name (full name) [Berkshire]:Kanagawa Locality Name (eg, city) [Newbury]:Kawasaki Organization Name (eg, company) [My Company Ltd]:company Organizational Unit Name (eg, section) []:kaihatubu Common Name (eg, your name or your server's hostname) []:192.168.0.2 Email Address []:[email protected] Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
| 項目 | 説明 |
|---|---|
| Country Name | 国名 |
| State or Province Name | 都道府県名 |
| Locality Name | 市区町村名 |
| Organization Name | 組織名 |
| Organizational Unit Name | 組織単位名 |
| Common Name | サイトの名前。 |
| Email Address | メールアドレス |
| A challenge password | 証明書を破棄する場合に必要になるパスワード |
| An optional company name | 別の組織名がある場合、その組織名 |
NATでサーバにプライベートアドレスを設定しているが、Common Nameには、プライベートIPアドレスを設定して接続した。ドメインを設定して、Apacheの仮想ホストを使って、固有の設定にすることが可能。
証明書の作成
公開鍵を含む。秘密鍵を使って暗号化し証明書を作成している。CAを使った場合はCAの公開鍵を使って証明書を複合化し公開鍵を取得するがこの場合は、公開鍵をどこから入手しているのだろうか?
# openssl x509 -in server.csr -days 365 -req -signkey server.key > server.crt
| オプション | 説明 |
|---|---|
| x509 | 証明書(certificate)の作成変換、 |
| -in arg | 入力ファイル |
| -days arg | 証明書の有効日数 |
| -req | ??? |
| -signkey arg | 秘密鍵ファイル |
apacheへの鍵の組み込み
テストのときは秘密鍵のパスフレーズを解除する。解除しないとapache起動時にパスフレーズを入力しなければならない。
# openssl rsa -in server.key_bk > server.key
とりあえず、CentOS付属のApacheのSSL設定ファイル(/etc/httpd/conf.d/ssl.conf)に以下を設定
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/ssl/server.crt
・・・
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/ssl/server.key
ログ
アクセスログ
httpd.confに設定
CustomLog logs/access_log combined
設定
設定ファイルディレクトリ
/etc/httpd/conf /etc/httpd/conf.d
アクセス制御
仮想ホスト
サーバのIPアドレスに複数の名前を割り当て、名前ごとに設定(ドキュメントルート、アクセス権など)を変える。
【例】
【例】
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
サーバの全てのインタフェースに対して、dummy-host.example.comにアクセスした場合は、上記の設定に従う。(ドキュメントルートは、/www/docs/dummy-host.example.comなど)
