2011-11-15 16 views
4

我在Apache 2.2上使用mod_userdir爲多個用戶提供了訪問Web服務器的權限(用於他們的測試和其他內容)。如何根據mod_userdir的用戶擁有不同的Apache2日誌文件?

我想給我的用戶訪問Apache日誌(以便他們可以調試他們的腳本),但日誌條目(包括ErrorLogCustomLogerror.log中的access.log)結合在一起(無論「用戶」目錄)。

有沒有辦法將日誌分成多個文件(取決於用戶)。

Apache的版本:2.2.16

的/ etc/apache2的/網站啓用/ 000-默認」 配置文件:啓用MODS-

<VirtualHost *:80> 
     ServerAdmin [email protected] 

     DocumentRoot /var/www 
     <Directory /> 
       Options FollowSymLinks 
       AllowOverride None 
     </Directory> 
     <Directory /var/www/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride None 
       Order allow,deny 
       allow from all 
     </Directory> 

     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
     <Directory "/usr/lib/cgi-bin"> 
       AllowOverride None 
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
       Order allow,deny 
       Allow from all 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     LogLevel warn 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 
</VirtualHost> 

的/ etc/apache2的/ /userdir.conf「配置文件:

<IfModule mod_userdir.c> 
     UserDir /home/*/public_html 
     UserDir disabled root 

     <Directory /home/*/public_html> 
       AllowOverride FileInfo AuthConfig Limit Options 
       Options MultiViews Indexes IncludesNoExec 
       IndexOptions FoldersFirst FancyIndexing IgnoreCase 
       php_admin_value open_basedir "..:/usr/share/php/" 
     </Directory> 

     ErrorLog /tmp/apache2-userdir-error.log 

     LogLevel warn 

     CustomLog /tmp/apache2-userdir-access.log 
</IfModule> 

回答

3

嗯...我99%肯定,你可以使用正則表達式捕獲組」 SetEnvI F」要做到這一點...

我沒有類似的東西 - 我採用分體式從網站的用戶登錄日誌(全部)折以下:

SetEnvIf Request_URI "^/~.*$" useraccess=1 

    CustomLog /var/www/logs/access.log combined env=!useraccess 
    CustomLog /var/www/logs/user-access.log combined env=useraccess 

你應該能夠做到:

SetEnvIf Request_URI "^/~([^/]+)/.*$" username=$1 
    CustomLog /var/www/logs/${username}.log combined 
+0

我錯過了'SetEnvIf'和'CustomLog'的實現......我的具體問題在這裏:http://stackoverflow.com/q/16154718/32836,並希望你的洞察力... – Jamie

+0

我收到了名爲'access _ $ {username} .log'的日誌文件。它沒有擴大變量。有任何想法嗎? – user1751825

+0

我也無法獲得變量擴展。我試過了一堆$ {},%{} e,引號和沒有引號的組合。我在這裏找到[鏈接](https://bz.apache.org/bugzilla/show_bug.cgi?id=59371)添加一個冒號擺脫了警告,但它仍然不擴大。 – bmsauer

1

根據Apache CustomLog Directive manual (mod_log_config module),可以將一個程序指定,而不是一個文件,這個程序會收到登錄到它的標準輸入。

然後,人們可以輕鬆地解析該日誌消息以檢查消息來自哪個路徑(從而哪個用戶)並將其寫入特定文件(例如由用戶名命名)。

相關問題