2

我想将 apache 配置为允许每个站点的 apache 日志记录(访问和错误)和每个主机的 php 变量分配。我有一个,所有站点都可以通过它访问:

http://domain/site1
http://domain/site2
...

如果我以这种方式使用 Alias 指令...

别名 /site1 /var/www/vhosts/httpdocs/site1
别名 /site2 /var/www/vhosts/httpdocs/site2

...我既不能按站点设置自定义日志记录,也不能按站点设置 php 变量。

所以我尝试使用VirtualHost指令但无法使其工作。我尝试在每个 VirtualHost 上的 ServerAlias 中使用domain/site1 ,但它不起作用。我也尝试直接在 VirtualHost指令中添加/site1 ,但我认为这是不允许的。我尝试了很多组合,但没有任何效果。我知道 VirtuaHosts 专注于使用多个域,但我想有针对这种情况的解决方案。

我也尝试过使用Directory指令,但其中不允许使用 CustomLog。有任何想法吗?

谢谢您的帮助。

艾托

4

1 回答 1

0

您是否将 vhost 定义插入到$HTTP_PATH/conf.d/vhost.confApache Web Server 的主配置文件所包含的 a 中:$HTTP_PATH/conf/httpd.conf

您是否检查了与 的php集成httpd.conf?加载php模块等

您是否检查了php.ini有关您的申请.htaccessphp要求的文件?

制作别名确实是一种糟糕的做法,除非您的服务器上的任何主机名都可以访问该网站......但不要忘记它肯定会在任何搜索引擎上降低您的分数。

请向我们提供更多信息,并减去 /var/log/httpd/error_log。

你可以得到它tail -f /path/to/error/log

补充: 可以看httpd模块mod_log_config。默认日志行的格式如下:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 

将其更改为:

LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

其中 %v 将在您的日志中插入虚拟主机的名称。这些名称将由下面指示的解析器显示和过滤。

并使用随 apache web 服务器分发的脚本来获取 virtualhosts 分隔的日志文件:著名的/src/support/split-logfile.pl

#!/usr/bin/perl
#
# ====================================================================
# Copyright (c) 1995-1998 The Apache Group.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer. 
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
#
# 3. All advertising materials mentioning features or use of this
#    software must display the following acknowledgment:
#    "This product includes software developed by the Apache Group
#    for use in the Apache HTTP server project (http://www.apache.org/)."
#
# 4. The names "Apache Server" and "Apache Group" must not be used to
#    endorse or promote products derived from this software without
#    prior written permission.  For permission please contact
#    Apache@Apache.Org.
#
# 5. Products derived from this software may not be called "Apache"
#    nor may "Apache" appear in their names without prior written
#    permission of the Apache Group.
#
# 6. Redistributions of any form whatsoever must retain the following
#    acknowledgment:
#    "This product includes software developed by the Apache Group
#    for use in the Apache HTTP server project (http://www.apache.org/)."
#
# THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
# ====================================================================
#
# This software consists of voluntary contributions made by many
# individuals on behalf of the Apache Group and was originally based
# on public domain software written at the National Center for
# Supercomputing Applications, University of Illinois, Urbana-Champaign.
# For more information on the Apache Group and the Apache HTTP server
# project, please see <http://www.apache.org/>.
#

#
# This script will take a combined Web server access
# log file and break its contents into separate files.
# It assumes that the first field of each line is the
# virtual host identity (put there by "%v"), and that
# the logfiles should be named that+".log" in the current
# directory.
#
# The combined log file is read from stdin. Records read
# will be appended to any existing log files.
#
%is_open = ();

while ($log_line = <STDIN>) {
    #
    # Get the first token from the log record; it's the
    # identity of the virtual host to which the record
    # applies.
    #
    ($vhost) = split (/\s/, $log_line);
    #
    # Normalize the virtual host name to all lowercase.
    # If it's blank, the request was handled by the default
    # server, so supply a default name.  This shouldn't
    # happen, but caution rocks.
    #
    $vhost = lc ($vhost) or "access";
    #
    # If the log file for this virtual host isn't opened
    # yet, do it now.
    #
    if (! $is_open{$vhost}) {
        open $vhost, ">>${vhost}.log"
            or die ("Can't open ${vhost}.log");
        $is_open{$vhost} = 1;
    }
    #
    # Strip off the first token (which may be null in the
    # case of the default server), and write the edited
    # record to the current log file.
    #
    $log_line =~ s/^\S*\s+//;
    printf $vhost "%s", $log_line;
}
exit 0;

如果这些还不够,您可以使用以下logcron脚本进行检查。您可以按照这些文章中的文字进行操作。

于 2012-09-11T15:55:59.010 回答