单个域中文件夹分隔站点的Apache VirtualHost配置

单个域中文件夹分隔站点的Apache VirtualHost配置,apache,Apache,我想将apache配置为允许每个站点的apache日志记录(访问和错误)和每个主机的php变量指定。我有一个单域,所有站点都可以通过它访问: http://domain/site1 http://domain/site2 ... http://domain/site1 http://domain/site2 ... 如果我这样使用Alias指令 Alias /site1 /var/www/vhosts/httpdocs/site1 Alias /site2 /var/www/vhosts/htt

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

http://domain/site1 http://domain/site2 ... http://domain/site1 http://domain/site2 ... 如果我这样使用Alias指令

Alias /site1 /var/www/vhosts/httpdocs/site1 Alias /site2 /var/www/vhosts/httpdocs/site2 别名/site1/var/www/vhosts/httpdocs/site1 别名/site2/var/www/vhosts/httpdocs/site2 。。。我既不能按站点设置自定义日志,也不能按站点设置php变量

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

我也尝试过使用目录DRACTIVE,但不允许在其中使用CustomLog。有什么想法吗

谢谢你的帮助


Aitor

您是否在Apache Web服务器主配置文件中包含的
$HTTP\u PATH/conf.d/vhost.conf
中插入了vhost定义:
$HTTP\u PATH/conf/httpd.conf

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

您是否检查了有关应用程序
.htaccess
&
php
要求的
php.ini
文件

创建别名确实是一种不好的方法,除非您的服务器上的任何主机名都可以访问该站点。。。但别忘了,它肯定会让你在任何搜索引擎上得分

请给我们更多信息,并加上/var/log/httpd/error\u log

您可以使用
tail-f/path/to/error/log

添加: 您可以查看httpd模块
mod\u log\u 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将在日志中插入虚拟主机的名称。 这些名称将由下面指定的解析器显示和过滤

并使用ApacheWeb服务器分发的脚本获取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;
#/usr/bin/perl
#
# ====================================================================
#版权所有(c)1995-1998阿帕奇集团。版权所有。
#
#以源代码和二进制形式重新分发和使用,带或不带
#如果满足以下条件,则允许进行修改
#满足以下条件:
#
# 1. 源代码的重新分发必须保留上述版权
#请注意,此条件列表和以下免责声明。
#
# 2. 以二进制形式重新分发必须复制上述版权
#请注意,此条件列表和中的以下免责声明
#随附的文件和/或其他材料
#分配。
#
# 3. 所有提及此功能或使用的广告材料
#软件必须显示以下确认信息:
#“此产品包括Apache Group开发的软件
#用于Apache HTTP服务器项目(http://www.apache.org/)."
#
# 4. 名称“Apache服务器”和“Apache组”不能用于
#认可或推广从本软件衍生的产品,而无需
#事先书面许可。如需许可,请联系
#    Apache@Apache.Org.
#
# 5. 从该软件派生的产品不能称为“Apache”
#未经事先书面同意,“Apache”也不得出现在其名称中
#Apache组的权限。
#
# 6. 任何形式的再分配都必须保留以下内容
#致谢:
#“此产品包括Apache Group开发的软件
#用于Apache HTTP服务器项目(http://www.apache.org/)."
#
#此软件由APACHE组“原样”和任何
#明示或默示保证,包括但不限于
#特定产品适销性和适用性的默示保证
#目的是否认。在任何情况下,APACHE集团或
#其出资人对任何直接、间接、附带,
#特殊、惩戒性或后果性损害(包括但不限于
#不限于采购替代货物或服务;
#使用、数据或利润损失;或业务中断)
#无论是何种原因造成的,且基于任何责任理论,无论是在合同中,
#严格责任或侵权行为(包括疏忽或其他)
#因使用本软件而产生的任何后果,即使建议
#这种损害的可能性。
# ====================================================================
#
#该软件由许多人的自愿捐款组成
#个人代表Apache集团,最初以
#关于国家信息技术中心编写的公共领域软件
超级计算应用,伊利诺伊大学,厄本那香槟。
#有关Apache组和Apache HTTP服务器的更多信息
#项目,请看。
#
#
#此脚本将采用组合Web服务器访问
#记录文件并将其内容拆分为单独的文件。
#它假定每行的第一个字段是
#虚拟主机标识(由“%v”放置),以及
#日志文件应在当前文件中命名为+“.log”
#目录。
#
#组合日志文件从stdin读取。读取记录
#将附加到任何现有日志文件。
#
%是开着吗;
而($log\u line=){
#
#从日志记录中获取第一个令牌;它是
#记录所指向的虚拟主机的标识
#适用。
#
($vhost)=拆分(/\s/,$log\u行);
#
#将虚拟主机名规范化为所有小写。
#如果为空,则默认情况下会处理该请求
#服务器,所以提供一个默认名称。这不应该
#发生了,但要小心石头。
#
$vhost=lc($vhost)或“访问”;
#
#如果