How to have separate Apache2 log files depending on the user of mod_userdir?

怎甘沉沦 提交于 2019-12-22 08:03:18

问题


I'm using mod_userdir on Apache 2.2 to give multiples users access to a web server (for their tests and other stuff).

I would like to give my users access to apache logs (so that they can debug their scripts) but log entries (both ErrorLog and CustomLog: error.log and access.log) are combined together (whatever "user" directory is concerned).

Is there a way to separate log into multiple files (depending of the user).

Apache version : 2.2.16

"/etc/apache2/sites-enabled/000-default" config file:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        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/mods-enabled/userdir.conf" config file:

<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>

回答1:


Hmmm... I'm 99% sure that you can use regex capture groups on "SetEnvIf" to do this...

I did something similar -- I split the user logs (all of them) off from the website logs using the following:

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

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

You should be able to do:

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



回答2:


According to Apache CustomLog Directive manual (mod_log_config module), a program can be specified instead of a file, this program will receive log into it's STDIN.

One could then easily parse that log message to check from which path the message is for (thus which user) and write it to a specific file (named by the user name for instance).



来源:https://stackoverflow.com/questions/8141130/how-to-have-separate-apache2-log-files-depending-on-the-user-of-mod-userdir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!