Apache-2.2

Apache:每個虛擬主機的自動日誌拆分?

  • August 5, 2011

每當我們在開發伺服器上創建新的虛擬主機時,我們總是必須手動指定單獨的訪問和錯誤日誌:

ErrorLog logs/mysite/dev1-error.log
CustomLog logs/mysite/dev1-access.log "common"

有沒有辦法讓 Apache 自動拆分日誌,而不必每次都指定它們?

我感受到你的痛苦,作為一名網路開發人員,我的本地開發人員中可能有超過 200 個虛擬主機 - 我個人並不關心日誌並將它們全部記錄到主 /var/log/apache …

然而,我所做的是編寫一個 shell 腳本來添加/管理我所有的虛擬主機 - 你需要做的就是調整它以將日誌寫入任何你喜歡的地方……

#!/bin/bash
ARGS=1
if [ "$1"X = "X" ];
       then
       echo "Must enter domain name"
       exit 0
fi
if [ "$2"X = "X" ];
       then
       echo "Must enter domain suffix"
       exit 0
fi
if [ "$3"X = "X" ];
       then
       echo "you must type "restart" if you want apache restarted "no" if not!"
       exit 0
fi

domain=$1.$2;

#echo $domain;
#exit 0


rm $domain.conf

echo "<VirtualHost *:80>" >> $domain.conf;
echo "        ServerAdmin no-reply@network.local" >> $domain.conf;
echo "        ServerName $1.network.local" >> $domain.conf;
echo "        DocumentRoot /Data/vhome/$1.$2/httpdocs" >> $domain.conf;
echo "        HostnameLookups Off" >> $domain.conf;
echo "        UseCanonicalName Off" >> $domain.conf;
echo "        ServerSignature On" >> $domain.conf;
echo "        ScriptAlias /cgi-bin/ "/Data/vhome/$1.$2/cgi-bin/"" >> $domain.conf;
echo "        ErrorLog /var/log/apache2/error_log" >> $domain.conf;
echo "        CustomLog /var/log/apache2/access_log combined" >> $domain.conf;
echo "    <Directory "/Data/vhome/$1.$2/cgi-bin">" >> $domain.conf;
echo "        AllowOverride All" >> $domain.conf;
echo "        Options +ExecCGI -Includes" >> $domain.conf;
echo "        Order allow,deny" >> $domain.conf;
echo "        Allow from all" >> $domain.conf;
echo "    </Directory>" >> $domain.conf;
echo "    <Directory "/Data/vhome/$1.$2/httpdocs">" >> $domain.conf;
echo "        Options Indexes FollowSymLinks" >> $domain.conf;
echo "        AllowOverride All" >> $domain.conf;
echo "        Order allow,deny" >> $domain.conf;
echo "        Allow from all" >> $domain.conf;
echo "    </Directory>" >> $domain.conf;
echo "       # #XSS prevention" >> $domain.conf;
echo "       # RewriteEngine On" >> $domain.conf;
echo "       # RewriteCond %(REQUEST_METHOD) ^TRACE" >> $domain.conf;
echo "       # RewriteRule .* -[F]" >> $domain.conf;
echo "</VirtualHost>" >> $domain.conf;

if [ "$3" = "restart" ];
       then
       rcapache2 restart;
fi

chmod 666 $domain.conf

cat $domain.conf
echo "Created!";

exit 0

希望能幫助到你。

-肖恩

引用自:https://serverfault.com/questions/298113