本文介绍了如何根据 mod_userdir 的用户拥有单独的 Apache2 日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Apache 2.2 上使用 mod_userdir 为多个用户提供访问网络服务器的权限(用于他们的测试和其他内容).

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

我想让我的用户访问 apache 日志(以便他们可以调试他们的脚本)但日志条目(ErrorLogCustomLog:error.logaccess.log) 组合在一起(不管用户"目录是什么).

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 版本:2.2.16

Apache version : 2.2.16

/etc/apache2/sites-enabled/000-default"配置文件:

<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" 配置文件:

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

推荐答案

嗯...我 99% 确定您可以在SetEnvIf"上使用正则表达式捕获组来执行此操作...

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

你应该能够做到:

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

这篇关于如何根据 mod_userdir 的用户拥有单独的 Apache2 日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 19:48