Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 在迁移到新服务器后,Perl CGI即时脚本的行为不符合预期_Apache_Perl_Timestamp_Debian_Cgi - Fatal编程技术网

Apache 在迁移到新服务器后,Perl CGI即时脚本的行为不符合预期

Apache 在迁移到新服务器后,Perl CGI即时脚本的行为不符合预期,apache,perl,timestamp,debian,cgi,Apache,Perl,Timestamp,Debian,Cgi,我有一个perl cgi脚本,多年来一直在FreeBSD 5.4 Apache1.3 Web服务器上完美地工作,没有遇到任何问题。这是一个每日图片脚本,它从给定目录中随机选择一张图片,以便包含在服务器端包含的shtml页面上 <!--#exec cgi="/cgi-bin/pod/pod.cgi"--> …这个脚本返回的是美国/洛杉矶时区的时间,而不是UTC。现在我不知道这个差异是否是导致我的每日图片脚本中出现错误的原因。但我的猜测是,以我有限的经验告诉我,这至少是可能的。但我已经

我有一个perl cgi脚本,多年来一直在FreeBSD 5.4 Apache1.3 Web服务器上完美地工作,没有遇到任何问题。这是一个每日图片脚本,它从给定目录中随机选择一张图片,以便包含在服务器端包含的shtml页面上

<!--#exec cgi="/cgi-bin/pod/pod.cgi"-->
…这个脚本返回的是美国/洛杉矶时区的时间,而不是UTC。现在我不知道这个差异是否是导致我的每日图片脚本中出现错误的原因。但我的猜测是,以我有限的经验告诉我,这至少是可能的。但我已经尽我的技术能力对脚本进行了调试/故障排除

我需要知道:

  • 是什么导致脚本在每次重新加载时返回新图片并更新日志文件,而不是在1天内保持静态
  • 它是由脚本中的意外(胖手指)错误引起的吗
  • 这是由于我的新服务器和/或其配置处理脚本的方式不同造成的吗
  • 它是由我在上一段中提到的时间戳/时区问题引起的吗
  • 或者这是因为我完全错过了什么
  • 接下来,我将提供脚本和apache配置文件的源代码。EXAMPLE.COM应在出现的任何地方替换为您的域名,并且文件路径应根据您的位置进行调整

    #!/usr/bin/perl
    
    ##############################################################
    #  POD (Picture of the Day) Version 1.30
    ##############################################################
    
    package VAR;
    use strict;
    
    ##############################################################
    #  Installation
    ##############################################################
    
    #  1. Edit path to Perl at top of script (pod.cgi) if it
    #  differs on your server. Usual and default path it
    #  [/usr/bin/perl]. However, on some servers it may be
    #  /usr/local/bin/perl. If in doubt, then refer to a script on
    #  your server that does work, or ask your web host. Edit
    #  variables below. Ensure you edit (and save) the script using
    #  an ASCII editor like Notepad.
    #
    #  2. Via FTP, create directory on server in CGI-BIN called
    #  pod. No need to CHMOD - you can leave set to server
    #  default directory permissions.
    #
    #  3. Via FTP, create subdirectory in 'pod' directory
    #  called data and CHMOD 777 (drwxrwxrwx).
    #
    #  4. FTP upload the pod.cgi script to the 'pod'
    #  directory in ASCII (text) and CHMOD 755 (rwxr-xr-x). You may
    #  need to rename the scripts with the .pl extension if your
    #  server uses the .pl extension for CGI-Perl scripts.
    #
    #  images/      755 (drwxr-xr-x)
    #  cgi-bin/pod/
    #   pod.cgi     755 (rwxr-xr-x)
    #   data/       777 (drwxrwxrwx)
    #
    
    ##############################################################
    #  Operation
    ##############################################################
    #
    #  METHOD 1: SSI Method
    #  ====================
    #  Call the script via SSI (Server-Side Includes). The image
    #  is embedded in the page. Insert the following SSI tag in
    #  the desired page:
    #
    #  <!--#exec cgi="/cgi-bin/pod/pod.cgi"-->
    #
    #  In either case, ensure to replace the cgi-bin/pod/ portion
    #  of the SSI tag with your path to the script.
    #
    #  If you get the [an error occurred while processing this
    #  directive] error message or no image / message displays,
    #  make sure (a) the path to Perl is correct, (b) the script
    #  was uploaded in ASCII, (c) the script is chmod 755
    #  (rwxr-xr-x) and (d) the path to the script in the SSI tag
    #  is correct - if in doubt, then ask your web host. If still
    #  problematic then try the following:
    #
    #  1. On most servers, the page with a SSI tag must be named
    #  with the SHTML extension in order for the server to parse
    #  and execute the SSI tag. Check the page source. If you
    #  still see the SSI tag, then it was not parsed. Try
    #  renaming the page with the SHTML extension. If the SSI tag
    #  is still not parsed (and still visible), then SSI may not
    #  be enabled on your server - ask your web host.
    #
    #  2. Try calling the script directly from the browser. If
    #  you get a server 500 error, then check your server error
    #  logs.
    #
    #  3. You can also try the following SSI tag:
    #
    #  <!--#include virtual="/cgi-bin/pod/pod.cgi"-->
    #
    #  METHOD 1: Non-SSI Method
    #  ====================
    #  You can also call the script directly from the browser:
    #
    #  http://www.yourdomain.com/cgi-bin/pod/pod.cgi
    #
    #  The image is NOT embedded, but is instead displayed in a
    #  script generated HTML page.
    
    ##############################################################
    #  Configuration
    ##############################################################
    
    #  Full (absolute) server directory path of directory holding
    #  image files for the POD script to draw from. Create this
    #  directory in advance and upload images (in Binary) to this
    #  directory. No need to chmod. NO trailing slash at end of
    #  path.
    $VAR::image_dir = "/var/www/EXAMPLE.COM/httpdocs/pod";
    
    #  URL of directory holding image files for the POD script to
    #  draw from. NO trailing slash at end of URL.
    $VAR::image_url = "http://www.EXAMPLE.COM/pod";
    
    #  Full (absolute) server directory path for script data files
    #  (pod.log, pod.err). Create this directory in advance and
    #  chmod (777 or drwxrwxrwx). NO trailing slash at end of path.
    $VAR::data_dir  = "/var/www/EXAMPLE.COM/httpdocs/pod/data";
    
    #  Output template - how POD image (or error message) is
    #  displayed. Feel free to change the HTML but (1) the MS link
    #  back MUST be retained and (2) the <%image%> tag MUST be
    #  retained as the tag is replaced with the image (or error
    #  message) HTML code.
    $VAR::template  = qq~
    <center>
    <table border="1">
            <th>
            <%image%>
            </th>
    </table>
    </center>
    ~;
    
    ##########################################################################
    #  Do NOT change or alter the code below!
    ##########################################################################
    
    eval {
        ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
        require 5.004;
    };
    if ($@) {
        print "Content-type: text/html\n\n";
        print "Server Error Message: $@\n";
        exit;
    }
    
    eval { &main; };
    if ($@) { &error ("[Error 01]: $@"); }
    exit;
    
    ###############################################
    # Main
    ###############################################
    sub main {
    
    my ($time, $date) = &get_time_stamp();
    my $num;
    
    if (-e "$VAR::data_dir/pod.log") {
        open (LOG, "$VAR::data_dir/pod.log") ||
        &error ("Error [02]: Cannot open pod.log file - $!");
        my @entries = <LOG>;
        close (LOG);
        chomp (@entries);
    
        my @match = grep (/^$date/, @entries);
        if (@match) {
            foreach (@match) {
                split (/\|/);
                if ($_[0] eq $date) {
                    $num = $_[1];
                    last;
                }
            }
        }
    }
    
    opendir (DIR, "$VAR::image_dir") || &error ("Error [03]: Cannot open $VAR::image - $!");
    my @files = sort (grep { m/.*\.gif|.jpg/ } readdir (DIR));
    closedir (DIR);
    
    if ($num eq "") { $num = int (rand @files); }
    my $image = @files[$num];
    if (! -e "$VAR::image_dir/$image") { &error ("Error [04]: Cannot find image file [$image]"); }
    
    my $tag = "<img src=\"$VAR::image_url/$image\">";
    $VAR::template =~ s/<%image%>/$tag/gis;
    print $VAR::template;
    
    my ($found, $newfile);
    if (-e "$VAR::data_dir/pod.log") {
        open (LOG, "$VAR::data_dir/pod.log") ||
        &error ("Error [05]: Cannot open pod.log file - $!");
        my @entries = <LOG>;
        close (LOG);
        chomp (@entries);
    
        foreach (@entries) {
            split (/\|/);
            if ($_[0] eq $date) {
                $_[2]++;
                $newfile .= "$date|$_[1]|$_[2]|$_[3]\n";
                $found++;
            }       
            else { $newfile .= "$_\n"; }
        }
        if (! $found) { $newfile .= "$date|$num|1|$image\n"; }
    
        open (LOG, ">$VAR::data_dir/pod.log") ||
        &error ("Error [06]: Cannot open pod.log file - $!");
        flock (LOG, 2) || &error ("Error [07]: Cannot lock pod.log file - $!");
        print LOG $newfile;
        close (LOG);
    }
    else {
        open (LOG, ">$VAR::data_dir/pod.log") ||
        &error ("Error [08]: Cannot open pod.log file - $!");
        print LOG "$date|$num|1|$image\n";
        close (LOG);
        chmod (0666, "$VAR::data_dir/pod.log") ||
        &error ("Error [09]: Cannot chmod pod.log file - $!");
    }
    }
    
    ###############################################
    # Get Time Stamp
    ###############################################
    sub get_time_stamp {
    
    my (@tb)    = localtime (time);
    my ($ap)    = "am";
    
    $tb[4]++;
    for (0..4) { $tb[$_] = sprintf ("%02d", $tb[$_]); }
    $tb[5] += 1900;
    $ap = "pm" if ($tb[2] >= 12);
    $tb[2] -= 12 if ($tb[2] > 12);
    
    my $date = "$tb[4]/$tb[3]/$tb[5]";
    return ("$tb[2]:$tb[1]:$tb[0]$ap $date", $date);
    }
    
    ###############################################
    # Error Handler
    ###############################################
    sub error {
    
    my $error       = shift;
    my ($time, $date)   = &get_time_stamp();
    
    my $tag         = "Cannot display image";
    $VAR::template      =~ s/<%image%>/$tag/gis;
    
    print $VAR::template;
    
    open (ERR, ">>$VAR::data_dir/pod.err");
    print ERR "$time | $ENV{'REMOTE_ADDR'} | $error\n";
    close (ERR);
    chmod (0666, "$VAR::data_dir/pod.err");
    exit;
    }
    ########################################
    #end of Picture of the Day script
    ########################################
    
    #/usr/bin/perl
    ##############################################################
    #POD(当日图片)1.30版
    ##############################################################
    包变量;
    严格使用;
    ##############################################################
    #装置
    ##############################################################
    #  1. 如果需要,请在脚本(pod.cgi)顶部编辑Perl的路径
    #在您的服务器上不同。通常和默认路径是什么
    #[/usr/bin/perl]。但是,在某些服务器上可能是
    #/usr/local/bin/perl。如果有疑问,请参阅
    #您的服务器是否正常工作,或者询问您的web主机。编辑
    #变量如下。确保使用编辑(并保存)脚本
    #类似记事本的ASCII编辑器。
    #
    #  2. 通过FTP,在CGI-BIN中的服务器上创建名为
    #豆荚。不需要CHMOD-您可以将设置保留为server
    #默认目录权限。
    #
    #  3. 通过FTP,在“pod”目录中创建子目录
    #称为数据和CHMOD 777(drwxrwx)。
    #
    #  4. FTP将pod.cgi脚本上载到“pod”
    #ASCII(文本)和CHMOD 755(rwxr-xr-x)格式的目录。你可以
    #如果您的
    #服务器对CGI Perl脚本使用.pl扩展名。
    #
    #图像/755(drwxr-xr-x)
    #cgi箱/吊舱/
    #pod.cgi 755(rwxr-xr-x)
    #数据/777(DRWXRWX)
    #
    ##############################################################
    #操作
    ##############################################################
    #
    #方法1:SSI法
    #  ====================
    #通过SSI调用脚本(服务器端包括)。形象
    #被嵌入到页面中。在中插入以下SSI标记
    #所需页面:
    #
    #  
    #
    #在任何一种情况下,确保更换cgi箱/吊舱/部分
    #SSI标记的路径以及脚本的路径。
    #
    #如果您得到[1],则在处理此文件时发生错误
    #指令]错误消息或无图像/消息显示,
    #确保(a)Perl的路径正确,(b)脚本正确
    #是以ASCII上传的,(c)脚本是chmod 755
    #(rwxr-xr-x)和(d)SSI标记中脚本的路径
    #是正确的-如果有疑问,请询问您的网络主机。如果仍然
    #然后尝试以下操作:
    #
    #  1. 在大多数服务器上,必须命名带有SSI标记的页面
    #使用SHTML扩展,以便服务器解析
    #并执行SSI标记。检查页面源代码。如果你
    #仍然看到SSI标记,则未对其进行分析。尝试
    #正在使用SHTML扩展名重命名页面。如果SSI标签
    #仍然没有被解析(并且仍然可见),那么SSI可能不会被解析
    #在您的服务器上启用-询问您的web主机。
    #
    #  2. 尝试直接从浏览器调用脚本。如果
    #出现服务器500错误,然后检查服务器错误
    #日志。
    #
    #  3. 您还可以尝试以下SSI标记:
    #
    #  
    #
    #方法1:非SSI方法
    #  ====================
    #也可以直接从浏览器调用脚本:
    #
    #  http://www.yourdomain.com/cgi-bin/pod/pod.cgi
    #
    #图像不会嵌入,而是显示在
    #脚本生成的HTML页面。
    ##############################################################
    #配置
    ##############################################################
    #目录保持的完整(绝对)服务器目录路径
    #POD脚本要从中绘制的图像文件。创造这个
    #提前将目录和图像(二进制)上载到此
    #目录。不需要使用chmod。结尾处没有尾随斜杠
    #路径。
    $VAR::image_dir=“/VAR/www/EXAMPLE.COM/httpdocs/pod”;
    #保存POD脚本要访问的图像文件的目录的URL
    #从中吸取教训。URL末尾没有尾随斜杠。
    $VAR::image_url=”http://www.EXAMPLE.COM/pod";
    #脚本数据文件的完整(绝对)服务器目录路径
    #(吊舱日志,吊舱错误)。提前创建此目录,然后
    #chmod(777或DRWXRWX)。路径的末尾没有尾随斜杠。
    $VAR::data_dir=“/VAR/www/EXAMPLE.COM/httpdocs/pod/data”;
    #输出模板-POD图像(或错误消息)的显示方式
    #显示。请随意更改HTML,但(1)MS链接
    #背面必须保留,(2)标签必须
    #标记替换为图像时保留(或错误
    #消息)HTML代码。
    $VAR::template=qq~
    ~;
    ##########################################################################
    #请勿更改或更改以下代码!
    ##########################################################################
    评估{
    ($0=~m,(.*)/[^/]+,)&取消移位(@INC,“$1”);
    要求5.004;
    };
    如果($@){
    
    #!/usr/bin/perl
    
    ##############################################################
    #  POD (Picture of the Day) Version 1.30
    ##############################################################
    
    package VAR;
    use strict;
    
    ##############################################################
    #  Installation
    ##############################################################
    
    #  1. Edit path to Perl at top of script (pod.cgi) if it
    #  differs on your server. Usual and default path it
    #  [/usr/bin/perl]. However, on some servers it may be
    #  /usr/local/bin/perl. If in doubt, then refer to a script on
    #  your server that does work, or ask your web host. Edit
    #  variables below. Ensure you edit (and save) the script using
    #  an ASCII editor like Notepad.
    #
    #  2. Via FTP, create directory on server in CGI-BIN called
    #  pod. No need to CHMOD - you can leave set to server
    #  default directory permissions.
    #
    #  3. Via FTP, create subdirectory in 'pod' directory
    #  called data and CHMOD 777 (drwxrwxrwx).
    #
    #  4. FTP upload the pod.cgi script to the 'pod'
    #  directory in ASCII (text) and CHMOD 755 (rwxr-xr-x). You may
    #  need to rename the scripts with the .pl extension if your
    #  server uses the .pl extension for CGI-Perl scripts.
    #
    #  images/      755 (drwxr-xr-x)
    #  cgi-bin/pod/
    #   pod.cgi     755 (rwxr-xr-x)
    #   data/       777 (drwxrwxrwx)
    #
    
    ##############################################################
    #  Operation
    ##############################################################
    #
    #  METHOD 1: SSI Method
    #  ====================
    #  Call the script via SSI (Server-Side Includes). The image
    #  is embedded in the page. Insert the following SSI tag in
    #  the desired page:
    #
    #  <!--#exec cgi="/cgi-bin/pod/pod.cgi"-->
    #
    #  In either case, ensure to replace the cgi-bin/pod/ portion
    #  of the SSI tag with your path to the script.
    #
    #  If you get the [an error occurred while processing this
    #  directive] error message or no image / message displays,
    #  make sure (a) the path to Perl is correct, (b) the script
    #  was uploaded in ASCII, (c) the script is chmod 755
    #  (rwxr-xr-x) and (d) the path to the script in the SSI tag
    #  is correct - if in doubt, then ask your web host. If still
    #  problematic then try the following:
    #
    #  1. On most servers, the page with a SSI tag must be named
    #  with the SHTML extension in order for the server to parse
    #  and execute the SSI tag. Check the page source. If you
    #  still see the SSI tag, then it was not parsed. Try
    #  renaming the page with the SHTML extension. If the SSI tag
    #  is still not parsed (and still visible), then SSI may not
    #  be enabled on your server - ask your web host.
    #
    #  2. Try calling the script directly from the browser. If
    #  you get a server 500 error, then check your server error
    #  logs.
    #
    #  3. You can also try the following SSI tag:
    #
    #  <!--#include virtual="/cgi-bin/pod/pod.cgi"-->
    #
    #  METHOD 1: Non-SSI Method
    #  ====================
    #  You can also call the script directly from the browser:
    #
    #  http://www.yourdomain.com/cgi-bin/pod/pod.cgi
    #
    #  The image is NOT embedded, but is instead displayed in a
    #  script generated HTML page.
    
    ##############################################################
    #  Configuration
    ##############################################################
    
    #  Full (absolute) server directory path of directory holding
    #  image files for the POD script to draw from. Create this
    #  directory in advance and upload images (in Binary) to this
    #  directory. No need to chmod. NO trailing slash at end of
    #  path.
    $VAR::image_dir = "/var/www/EXAMPLE.COM/httpdocs/pod";
    
    #  URL of directory holding image files for the POD script to
    #  draw from. NO trailing slash at end of URL.
    $VAR::image_url = "http://www.EXAMPLE.COM/pod";
    
    #  Full (absolute) server directory path for script data files
    #  (pod.log, pod.err). Create this directory in advance and
    #  chmod (777 or drwxrwxrwx). NO trailing slash at end of path.
    $VAR::data_dir  = "/var/www/EXAMPLE.COM/httpdocs/pod/data";
    
    #  Output template - how POD image (or error message) is
    #  displayed. Feel free to change the HTML but (1) the MS link
    #  back MUST be retained and (2) the <%image%> tag MUST be
    #  retained as the tag is replaced with the image (or error
    #  message) HTML code.
    $VAR::template  = qq~
    <center>
    <table border="1">
            <th>
            <%image%>
            </th>
    </table>
    </center>
    ~;
    
    ##########################################################################
    #  Do NOT change or alter the code below!
    ##########################################################################
    
    eval {
        ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
        require 5.004;
    };
    if ($@) {
        print "Content-type: text/html\n\n";
        print "Server Error Message: $@\n";
        exit;
    }
    
    eval { &main; };
    if ($@) { &error ("[Error 01]: $@"); }
    exit;
    
    ###############################################
    # Main
    ###############################################
    sub main {
    
    my ($time, $date) = &get_time_stamp();
    my $num;
    
    if (-e "$VAR::data_dir/pod.log") {
        open (LOG, "$VAR::data_dir/pod.log") ||
        &error ("Error [02]: Cannot open pod.log file - $!");
        my @entries = <LOG>;
        close (LOG);
        chomp (@entries);
    
        my @match = grep (/^$date/, @entries);
        if (@match) {
            foreach (@match) {
                split (/\|/);
                if ($_[0] eq $date) {
                    $num = $_[1];
                    last;
                }
            }
        }
    }
    
    opendir (DIR, "$VAR::image_dir") || &error ("Error [03]: Cannot open $VAR::image - $!");
    my @files = sort (grep { m/.*\.gif|.jpg/ } readdir (DIR));
    closedir (DIR);
    
    if ($num eq "") { $num = int (rand @files); }
    my $image = @files[$num];
    if (! -e "$VAR::image_dir/$image") { &error ("Error [04]: Cannot find image file [$image]"); }
    
    my $tag = "<img src=\"$VAR::image_url/$image\">";
    $VAR::template =~ s/<%image%>/$tag/gis;
    print $VAR::template;
    
    my ($found, $newfile);
    if (-e "$VAR::data_dir/pod.log") {
        open (LOG, "$VAR::data_dir/pod.log") ||
        &error ("Error [05]: Cannot open pod.log file - $!");
        my @entries = <LOG>;
        close (LOG);
        chomp (@entries);
    
        foreach (@entries) {
            split (/\|/);
            if ($_[0] eq $date) {
                $_[2]++;
                $newfile .= "$date|$_[1]|$_[2]|$_[3]\n";
                $found++;
            }       
            else { $newfile .= "$_\n"; }
        }
        if (! $found) { $newfile .= "$date|$num|1|$image\n"; }
    
        open (LOG, ">$VAR::data_dir/pod.log") ||
        &error ("Error [06]: Cannot open pod.log file - $!");
        flock (LOG, 2) || &error ("Error [07]: Cannot lock pod.log file - $!");
        print LOG $newfile;
        close (LOG);
    }
    else {
        open (LOG, ">$VAR::data_dir/pod.log") ||
        &error ("Error [08]: Cannot open pod.log file - $!");
        print LOG "$date|$num|1|$image\n";
        close (LOG);
        chmod (0666, "$VAR::data_dir/pod.log") ||
        &error ("Error [09]: Cannot chmod pod.log file - $!");
    }
    }
    
    ###############################################
    # Get Time Stamp
    ###############################################
    sub get_time_stamp {
    
    my (@tb)    = localtime (time);
    my ($ap)    = "am";
    
    $tb[4]++;
    for (0..4) { $tb[$_] = sprintf ("%02d", $tb[$_]); }
    $tb[5] += 1900;
    $ap = "pm" if ($tb[2] >= 12);
    $tb[2] -= 12 if ($tb[2] > 12);
    
    my $date = "$tb[4]/$tb[3]/$tb[5]";
    return ("$tb[2]:$tb[1]:$tb[0]$ap $date", $date);
    }
    
    ###############################################
    # Error Handler
    ###############################################
    sub error {
    
    my $error       = shift;
    my ($time, $date)   = &get_time_stamp();
    
    my $tag         = "Cannot display image";
    $VAR::template      =~ s/<%image%>/$tag/gis;
    
    print $VAR::template;
    
    open (ERR, ">>$VAR::data_dir/pod.err");
    print ERR "$time | $ENV{'REMOTE_ADDR'} | $error\n";
    close (ERR);
    chmod (0666, "$VAR::data_dir/pod.err");
    exit;
    }
    ########################################
    #end of Picture of the Day script
    ########################################
    
    # configuration directives that give the server its instructions.
    # See http://httpd.apache.org/docs/2.4/ for detailed information about
    # the directives and /usr/share/doc/apache2/README.Debian about Debian specific
    # hints.
    #
    #
    # Summary of how the Apache 2 configuration works in Debian:
    # The Apache 2 web server configuration in Debian is quite different to
    # upstream's suggested way to configure the web server. This is because Debian's
    # default Apache2 installation attempts to make adding and removing modules,
    # virtual hosts, and extra configuration directives as flexible as possible, in
    # order to make automating the changes and administering the server as easy as
    # possible.
    
    # It is split into several files forming the configuration hierarchy outlined
    # below, all located in the /etc/apache2/ directory:
    #
    #       /etc/apache2/
    #       |-- apache2.conf
    #       |       `--  ports.conf
    #       |-- mods-enabled
    #       |       |-- *.load
    #       |       `-- *.conf
    #       |-- conf-enabled
    #       |       `-- *.conf
    #       `-- sites-enabled
    #               `-- *.conf
    #
    #
    # * apache2.conf is the main configuration file (this file). It puts the pieces
    #   together by including all remaining configuration files when starting up the
    #   web server.
    #
    # * ports.conf is always included from the main configuration file. It is
    #   supposed to determine listening ports for incoming connections which can be
    #   customized anytime.
    #
    # * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
    #   directories contain particular configuration snippets which manage modules,
    #   global configuration fragments, or virtual host configurations,
    #   respectively.
    #
    #   They are activated by symlinking available configuration files from their
    #   respective *-available/ counterparts. These should be managed by using our
    #   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
    #   their respective man pages for detailed information.
    #
    # * The binary is called apache2. Due to the use of environment variables, in
    #   the default configuration, apache2 needs to be started/stopped with
    #   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
    #   work with the default configuration.
    
    
    # Global configuration
    #
    
    #
    # ServerRoot: The top of the directory tree under which the server's
    # configuration, error, and log files are kept.
    #
    # NOTE!  If you intend to place this on an NFS (or otherwise network)
    # mounted filesystem then please read the Mutex documentation (available
    # at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
    # you will save yourself a lot of trouble.
    #
    # Do NOT add a slash at the end of the directory path.
    #
    #ServerRoot "/etc/apache2"
    
    # Set timezone for apache
      SetEnv TZ America/Los_Angeles
    
    #
    # The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
    #
    Mutex file:${APACHE_LOCK_DIR} default
    
    #
    # The directory where shm and other runtime files will be stored.
    #
    
    DefaultRuntimeDir ${APACHE_RUN_DIR}
    
    #
    # PidFile: The file in which the server should record its process
    # identification number when it starts.
    # This needs to be set in /etc/apache2/envvars
    #
    PidFile ${APACHE_PID_FILE}
    
    #
    # Timeout: The number of seconds before receives and sends time out.
    #
    Timeout 300
    
    #
    # KeepAlive: Whether or not to allow persistent connections (more than
    # one request per connection). Set to "Off" to deactivate.
    #
    KeepAlive On
    
    #
    # MaxKeepAliveRequests: The maximum number of requests to allow
    # during a persistent connection. Set to 0 to allow an unlimited amount.
    # We recommend you leave this number high, for maximum performance.
    #
    MaxKeepAliveRequests 500
    
    #
    # KeepAliveTimeout: Number of seconds to wait for the next request from the
    # same client on the same connection.
    #
    KeepAliveTimeout 5
    
    
    # These need to be set in /etc/apache2/envvars
    User ${APACHE_RUN_USER}
    Group ${APACHE_RUN_GROUP}
    
    #
    # HostnameLookups: Log the names of clients or just their IP addresses
    # e.g., www.apache.org (on) or 204.62.129.132 (off).
    # The default is off because it'd be overall better for the net if people
    # had to knowingly turn this feature on, since enabling it means that
    # each client request will result in AT LEAST one lookup request to the
    # nameserver.
    #
    HostnameLookups Off
    
    # ErrorLog: The location of the error log file.
    # If you do not specify an ErrorLog directive within a <VirtualHost>
    # container, error messages relating to that virtual host will be
    # logged here.  If you *do* define an error logfile for a <VirtualHost>
    # container, that host's errors will be logged there and not here.
    #
    ErrorLog ${APACHE_LOG_DIR}/error.log
    
    #
    # LogLevel: Control the severity of messages logged to the error_log.
    # Available values: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the log level for particular modules, e.g.
    # "LogLevel info ssl:warn"
    #
    LogLevel warn
    
    # Include module configuration:
    IncludeOptional mods-enabled/*.load
    IncludeOptional mods-enabled/*.conf
    
    # Include list of ports to listen on
    Include ports.conf
    
    
    # Sets the default security model of the Apache2 HTTPD server. It does
    # not allow access to the root filesystem outside of /usr/share and /var/www.
    # The former is used by web applications packaged in Debian,
    # the latter may be used for local directories served by the web server. If
    # your system is serving content from a sub-directory in /srv you must allow
    # access here, or in any related virtual host.
    <Directory />
            Options FollowSymLinks
            AllowOverride None
            Require all denied
    </Directory>
    
    <Directory /usr/share>
            AllowOverride None
            Require all granted
    </Directory>
    
    <Directory /var/www/>
            Options -Indexes +FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>
    
    #<Directory /srv/>
    #       Options Indexes FollowSymLinks
    #       AllowOverride None
    #       Require all granted
    #</Directory>
    # AccessFileName: The name of the file to look for in each directory
    # for additional configuration directives.  See also the AllowOverride
    # directive.
    #
    AccessFileName .htaccess
    #
    # The following lines prevent .htaccess and .htpasswd files from being
    # viewed by Web clients.
    #
    <FilesMatch "^\.ht">
            Require all denied
    </FilesMatch>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive.
    #
    # These deviate from the Common Log Format definitions in that they use %O
    # (the actual bytes sent including headers) instead of %b (the size of the
    # requested file), because the latter makes it impossible to detect partial
    # requests.
    #
    # Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
    # Use mod_remoteip instead.
    #
    LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
    LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %O" common
    LogFormat "%{Referer}i -> %U" referer
    LogFormat "%{User-agent}i" agent
    # Include of directories ignores editors' and dpkg's backup files,
    # see README.Debian for details.
    # Include generic snippets of statements
    IncludeOptional conf-enabled/*.conf
    # Include the virtual host configurations:
    IncludeOptional sites-enabled/*.conf
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
    
    <VirtualHost *:80>
        ServerName EXAMPLE.com
        ServerAlias www.EXAMPLE.com
        UseCanonicalName Off
        ServerAlias  EXAMPLE1.com
        ServerAlias  www.EXAMPLE1.com
        ServerAlias  EXAMPLE2.com
        ServerAlias  www.EXAMPLE2.com
        ServerAlias  EXAMPLE.co.uk
        ServerAlias  www.EXAMPLE.co.uk
        ServerAlias  EXAMPLE.net
        ServerAlias  www.EXAMPLE.net
        ServerAlias  EXAMPLE3.com
        ServerAlias  www.EXAMPLE3.com
        ServerAdmin EXAMPLEd@gmail.com
        DocumentRoot /var/www/EXAMPLE.com/httpdocs
        <Directory /var/www/EXAMPLE.com/httpdocs>
            Options -Indexes +FollowSymLinks
            AllowOverride All
        </Directory>
        ScriptAlias "/cgi-bin/" "/var/www/EXAMPLE.com/cgi-bin/"
        #<Directory "/var/www/EXAMPLE.com/cgi-bin/">
        #    Options +ExecCGI
        #    AddHandler cgi-script .cgi
        #    AllowOverride All    
        #</Directory>
        #<Directory "/var/www/EXAMPLE.com/httpdocs/members/cgi-bin">
        #    Options +ExecCGI
        #    AddHandler cgi-script .cgi
        #    AllowOverride All
        #</Directory>
        #<Directory "/var/www/EXAMPLE.com/httpdocs/pod">
        #    Options +ExecCGI
        #    AddHandler cgi-script .cgi
        #    AllowOverride All
        #</Directory>
    
        Alias "/passwd/" "/var/www/EXAMPLE.com/passwd/"
    
        <IfModule mod_ssl.c>
            SSLEngine off
        </IfModule>
    
        <Directory /var/www/EXAMPLE.com>
            Options +ExecCGI +FollowSymLinks +Includes
            AddHandler cgi-script .cgi
            AllowOverride All
        </Directory>
    
        <Directory /var/www/EXAMPLE.com>
            <IfModule sapi_apache2.c>
                    php_admin_flag engine on
                    php_admin_flag safe_mode on
                    php_admin_value open_basedir "/var/www/EXAMPLE.com/httpdocs:/tmp"
            </IfModule>
            <IfModule mod_php5.c>
                    php_admin_flag engine on
                    php_admin_flag safe_mode on
                    php_admin_value open_basedir "/var/www/EXAMPLE.com/httpdocs:/tmp"
            </IfModule>
        </Directory>
    
        <Directory /var/www/EXAMPLE.com>
            RewriteEngine on
    
            # the following section prevents outside sites from hot-linking photos
            # leave this next line in allow empty referrers, remove to disallow empty referrers
            RewriteCond %{HTTP_REFERER} !^$ [NC]
            RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*XX\.XXX\.XXX\.XXX(:[0-9]+)?(/.*)?$ [NC]
            RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*EXAMPLE\.com(:[0-9]+)?(/.*)?$ [NC]
            RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*EXAMPLE\.org(:[0-9]+)?(/.*)?$ [NC]
            RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*EXAMPLE\.net(:[0-9]+)?(/.*)?$ [NC]
            RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*EXAMPLE\.co.uk(:[0-9]+)?(/.*)?$ [NC]
            RewriteCond %{HTTP_REFERER} !^http://(.*@)?([a-z0-9-]+\.)*EXAMPLE\.de(:[0-9]+)?(/.*)?$ [NC]
            RewriteCond %{HTTP_REFERER} !^http://(.*@)?1\.2\.3\.4(:[0-9]+)?(/.*)?$
            RewriteRule .*\.(gif|jpeg|jpg)$ - [NC,F,L]
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/EXAMPLE.com-error.log
        CustomLog ${APACHE_LOG_DIR}/EXAMPLE.com-access.log combined
        # sends 404-not-found errors to error page
        ErrorDocument 404 /404-error-page.html
    
        # makes server side includes work on all html pages
        AddType text/html .shtml .html .htm
        AddHandler server-parsed .shtml .html .htm
    
        RewriteEngine On
    
        # If the hostname is NOT www.domain.com
        # RewriteCond %{HTTP_HOST} !^www\.EXAMPLE\.com$
        # 301 redirect to the same resource on www.EXAMPLE.com
        # RewriteRule (.*) http://www.EXAMPLE.com$1 [L,R=301]
    
        # sets the web surfer's browser to cache images, style sheets, and JavaScript for a week
        <IfModule mod_headers.c>
        # WEEK
        <FilesMatch "\.(jpg|jpeg|png|gif|swf|js|css)$">
            Header set Cache-Control "max-age=604800, public"
        </FilesMatch>
        </IfModule>
    
    </VirtualHost>
    
    split (/\|/);
    
    @_ = split (/\|/);