at_yasu's blog

ロード的なことを

複数のVirtual Hostを持つ時にする設定

書いてなかったので。

Apacheの設定は、「*.conf」などが使えますので、httpd.confの末尾に「Include file/to/path/*.conf」とでも書いておき、file/to/path/ 以下にVirtual Hostの設定ファイル一覧を置いておけば、自動的に読みます。


例えば、「hoge.example.com.conf」「huga.examle.com.conf」の二つを設定したい場合は、file/to/path/以下にそのファイルを置きます。



以下、Djangoに使う際のVirtualHostテンプレ。使う際は、sed -e s/@domain@/ドメイン名/g で置換してくだせぃ。

# $Id: django.conf,v 1.2 2008/11/26 11:53:41 yasui Exp $
# $Date: 2008/11/26 11:53:41 $

<VirtualHost *:80>
        <IfModule !mod_python.c>
                LoadModule python_module libexec/apache22/mod_python.so
        </IfModule>
        DocumentRoot /home/@domain@/@domain@/trank/public_html/
        ServerName @domain@
        CustomLog /home/@domain@/log/@domain@.access.log combined
        ErrorLog /home/@domain@/log/@domain@.error.log

        <Directory />
                AllowOverride All
                Options All 
        </Directory>

        <Location "/">
                SetHandler Python-program
                PythonHandler django.core.handlers.modpython
                SetEnv DJANGO_SETTINGS_MODULE ginger.settings 
                PythonAutoReload Off
                PythonPath "['/home/@domain@/@domain@/trank'] + sys.path"

# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

        </Location>

        <Location "/media">
                SetHandler None
        </Location>

</VirtualHost>