我們可以在哪個文件中修改 apache 記錄/未記錄的內容?

我們可以在哪個文件中修改 apache 記錄/未記錄的內容?

我有一個帶有 Apache 的 Debian 8。我的/etc/apache2/sites-available/000-default.conf就像下面這樣。
我可以詢問 Apache 如何以及在哪個設定檔中不登入/var/log/apache2/other_vhosts_access.log來自以下位置的流量http://www.mysite2.org或來自http://www.mysite3.org/subdir/所有其餘的內容都應像往常一樣記錄到同一文件中other_vhosts_access.log

<VirtualHost *:80>
  ServerName www.mysite1.org
  DocumentRoot /home/www/mysite1
  <Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName www.mysite2.org
  DocumentRoot /home/www/mysite2
  <Directory />
  ...
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName www.mysite3.org
  DocumentRoot /home/www/mysite3
  <Directory />
  ...
  </Directory>
</VirtualHost>

+ 10 other virtual hosts

答案1

每個虛擬主機都需要定義錯誤日誌和通用日誌,如果沒有這些,則使用預設日誌,另請注意,值得建立一個預設虛擬主機,它可以捕獲不屬於您的網域之一的所有流量(將其dns指向您網站的人) )。這可能會對搜尋結果產生不良後果,因為它是欺騙內容。

所以,在每個虛擬主機中;

    ErrorLog "logs/web1-error_log"
    CustomLog "logs/web1-access_log" common

    ErrorLog "logs/web2-error_log"
    CustomLog "logs/web2-access_log" common

更新:

沒有看到關於不記錄特定目錄的部分,這可以透過設定環境變數來實現。

答案2

感謝@MikeJonesey 的回答。要添加更多詳細信息,這是解決方案,請輸入/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
  ServerName www.mysite3.org
  DocumentRoot /home/www/mysite3
  <Directory />
  ...
  </Directory>
  SetEnvIf Request_URI "^/subdir(.*)$" dontlog
  CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined env=!dontlog
</VirtualHost>

相關內容