Apache VirtualHostの効率的な管理方法

ってどうするのが良いのでしょうか。今回の条件は下記として...

  • 開発環境。
  • 複数サービスのVirtualHostを立てたい。
  • 開発環境なのでSSLはとりあえずオレオレ証明書を使いまわす。

とりあえず最近は、開発環境向けにこんな感じで設定している。
設定が変わるたびにいろいろな箇所を修正するのが大変なので、可能な限り共通部分は別ファイルに切りだしてIncludeするように。

conf/
  httpd.conf
conf.d/
  vhost/
    example.com.conf
    _example.com.conf
    _ssl.conf
  • サーバ全体に対する設定はhttpd.confとconf.d/*.confに記述。
  • httpd.confの末尾で、VirtualHostの設定ファイルをInclude。
  • conf.d/vhost 以下に example.com.conf のようなドメイン別ファイルを用意。
  • 80番,443番で共通の設定は _example.com.confのようにドメイン内の共通ファイルを作成し、ドメイン別ファイルからIncludeする。
  • SSLでの共通設定はドメインを超えて _ssl.conf に記述し、各ドメイン別ファイルからIncludeする。

いろいろ端折ってるけどファイルの中身はこんな感じ。

conf/httpd.conf

# ...上部でサーバ全体向けの設定
NameVirtualHost *:80
NameVirtualHost *:443
Include conf.d/vhost/example.com

conf.d/vhost/example.com.conf

<VirtualHost *:80>
    Include conf.d/vhost/_example.com.conf
</VirtualHost>
<VirtualHost *:443>
    Include conf.d/vhost/_example.com.conf
    Include conf.d/vhost/_ssl.conf
</VirtualHost>

conf.d/vhost/_example.com.conf

ServerName example.com
ServerAlias www.example.com

DirectoryIndex index.php
DocumentRoot "/path/to/example.com/www"
<Directory "/path/to/example.com/www">
    AllowOverride All
    Allow from All
</Directory>

CustomLog logs/example.com/access_log combined
ErrorLog logs/example.com/error_log

conf.d/vhost/_ssl.conf

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0    

で、サービスのVirtualHostを追加するごとに、example.com.conf, _example.com.confが増えていく感じ。