mod_vhost_aliasがすごかったw
httpd.confの
LoadModule vhost_alias_module modules/mod_vhost_alias.so
を有効にして、
<VirtualHost *:80>
ServerAdmin webmaster@%0
VirtualDocumentRoot /www/%0/public_html/
VirtualScriptAlias /www/%0/cgi-bin/
<Directory “/www/*/public_html”>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
ExpiresActive On
ExpiresByType image/gif “access plus 1 days”
ExpiresByType image/jpg “access plus 1 days”
ExpiresByType image/jpeg “access plus 1 days”
ExpiresByType image/png “access plus 30 days”
ExpiresByType application/x-javascript “access plus 20 days”
ExpiresByType text/css “access plus 20 days”
</Directory>
</VirtualHost>
これでこの階層にディレクトリを作れば、apacheを再起動しなくても自動でサイトが作れちゃう。
こんな書き方もできるよ
<VirtualHost *:80> ServerAdmin info@example.com ServerName example.com ServerAlias *.example.com VirtualDocumentRoot /home/%2/public_html/%1 ErrorLog logs/example.com-error_log CustomLog logs/example.com-access_log common </VirtualHost>
sub.example.com の場合 %0 = sub.example.com %1 = sub %1+ = sub.example.com %2 = example %2+ = example.com
Comment