Apache 虚拟主机故障排除

Apache 虚拟主机故障排除

使用此配置时遇到一些问题:

<VirtualHost *:80>
    ServerAdmin **************
    ServerName nagios.vdb.local
    ServerAlias nagios

    DocumentRoot /usr/local/nagios/share

    ErrorLog /var/www/vhosts/nagios/logs/error.log

    LogLevel warn

    CustomLog /var/www/vhosts/nagios/logs/access.log combined

    ServerSignature Off

    ###################
    ###  CONFIG NAGIOS  ###
    ##################

    ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

    <Directory "/usr/local/nagios/sbin">
       Options ExecCGI
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from 10.1.1.0/24

       AuthBasicProvider ldap
       AuthzLDAPAuthoritative off
       AuthLDAPURL ldap://10.1.1.*****************?sAMAccountName?sub?(memberOf=**************)
       AuthLDAPBindDN cn=A***********
       AuthLDAPBindPassword ***********
       AuthType Basic
       AuthName "Nagios Access LDAP"
       Require valid-user
    </Directory>

    Alias /nagios "/usr/local/nagios/share"
    Alias /massAck "/usr/local/nagios/share/NagiosPlus/massAckTool/massAck.php"

    <Directory "/usr/local/nagios/share">
       Options None
       DirectoryIndex index.php
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from 10.1.1.0/24

       AuthBasicProvider ldap
       AuthzLDAPAuthoritative off
       AuthLDAPURL ldap://10.1.1.**************?sAMAccountName?sub?(memberOf=************)
       AuthLDAPBindDN cn=A*************
       AuthLDAPBindPassword ************
       AuthType Basic
       AuthName "Nagios Access LDAP"
       Require valid-user
    </Directory>

    ###################
    ###    CONFIG NRDP    ###
    ##################

    Alias /nrdp "/usr/local/nrdp"

    <Directory "/usr/local/nrdp">
    #  SSLRequireSSL
       Options None
       AllowOverride None
       Order deny,allow
       Allow from 10.1.1.0/24

       AuthBasicProvider ldap
       AuthzLDAPAuthoritative off
       AuthLDAPURL ldap://10.1.1.************?sAMAccountName?sub?(memberOf=***********)
       AuthLDAPBindDN cn=A************
       AuthLDAPBindPassword *********
       AuthType Basic
       AuthName "Nagios Access LDAP"
       Require valid-user
    </Directory>

    #####################
    ### CONFIG Nagiosgraph ###
    ###################

    # enable nagiosgraph CSS and JavaScript
    Alias /nagiosgraph "/usr/local/nagiosgraph/share"

    ScriptAlias /nagiosgraph/cgi-bin "/usr/local/nagiosgraph/cgi"
    <Directory "/usr/local/nagiosgraph/cgi">
       Options ExecCGI
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from 10.1.1.0/24
       AuthBasicProvider ldap
       AuthzLDAPAuthoritative off
       AuthLDAPURL ldap://10.1.1.**********?sAMAccountName?sub?(memberOf=**********)
       AuthLDAPBindDN cn=A*******
       AuthLDAPBindPassword **********
       AuthType Basic
       AuthName "Nagios Access LDAP"
       Require valid-user
    </Directory>

    <Directory "/usr/local/nagiosgraph/share">
       Options None
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from 10.1.1.0/24
    </Directory>

    ##################
    ###    CONFIG Cacti   ###
    #################

    Alias /cacti /usr/local/cacti/

    <Directory "/usr/local/cacti/">
        Options Indexes
        AllowOverride AuthConfig Options
        Order deny,allow
        Deny from all
        Allow from 10.1.1.0/24
    </Directory>

    <Directory /usr/local/cacti/plugins/weathermap>
        <Files editor.php>
            Order Deny,Allow
            Deny from all
            Allow from 10.1.1.232
        </Files>
    </Directory>

    ##################
    ###    CONFIG GLPI   ###
    #################

    Alias /glpi /usr/local/glpi/
    <Directory "/usr/local/glpi">
        Options None
        AllowOverride AuthConfig Options
        Order deny,allow
        Deny from all
        Allow from 10.1.1.0/24
    </Directory>

    ####################
    ###    CONFIG VSHELL   ###
    ##################

    Alias /vshell2 "/usr/local/vshell2"

    <Directory "/usr/local/vshell2">
       Options None
       Options FollowSymLinks
       AllowOverride All
       Order deny,allow
       Deny from all
       Allow from 10.1.1.0/24

       AuthBasicProvider ldap
       AuthzLDAPAuthoritative off
       AuthLDAPURL ldap://10.1.1.******?sAMAccountName?sub?(memberOf=*************)
       AuthLDAPBindDN cn=Ap***********
       AuthLDAPBindPassword *******
       AuthType Basic
       AuthName "Nagios Access LDAP"
       Require valid-user
    </Directory>

</VirtualHost>

我的 IP 是 10.1.1.132,所以通常情况下,我必须访问此虚拟主机中的任何内容。我已经停用了其他配置,因此安装了主 httpd.conf,没有任何不匹配的情况。但我遇到了以下问题:

  • 重新启动 Apache 时,收到一条消息:

Starting httpd: [Wed Jun 01 10:35:40 2016] [warn] The ScriptAlias directive in /etc/httpd/vhosts.d/nagios.vdb.local.conf at line 104 will probably never match because it overlaps an earlier Alias.

就是这一行:

ScriptAlias /nagiosgraph/cgi-bin "/usr/local/nagiosgraph/cgi"

这是我第一次加载它,因为我在 conf.d 目录中使用了它,我已通过注释Include conf.d/*.confhttpd.conf 中的行来禁用它...

-访问 nagios.vdb.local,出现 DNS 错误 --> 因此我将改用服务器 IP,用于生产目的

  • 访问 /nagios :一切似乎都很好,即使CGI 需要页面重新加载才能首次被接受,我不明白为什么……

  • 访问/massAck:获取主页代码(.php),它将不会被执行,所以我可能错过了一个指令

  • 访问/nrdp:禁止访问

  • 访问/nagiosgraph:禁止访问

  • 访问 /cacti:获得目录索引

  • 访问/glpi:禁止访问

  • 访问 /vshell2:我有主页,但它不会显示连接。请注意,使用没有虚拟主机的别名,一切都很好。

是否有一个指令首先在虚拟主机中执行 php ?以及如何解决我在虚拟主机中被禁止访问的问题(不使用虚拟主机时使用别名工作)?

答案1

我的 apache2 技能并不出色,但也许这会有所帮助:

https://httpd.apache.org/docs/current/mod/mod_alias.html

首先,所有重定向都在处理别名之前进行处理,因此与重定向或 RedirectMatch 匹配的请求永远不会应用别名。其次,别名和重定向按照它们在配置文件中出现的顺序进行处理,第一个匹配的优先。

因此,当两个或多个指令应用于同一子路径时,必须首先列出最具体的路径,以便所有指令都能生效。例如,以下配置将按预期工作:

别名“/foo/bar”“/baz”
别名“/foo”“/gaq”

但是如果按顺序反转上述两个指令,/foo 别名将始终在 /foo/bar 别名之前匹配,因此后一个指令将被忽略。

也许你应该尝试交换位置

Alias /nagiosgraph "/usr/local/nagiosgraph/share"
ScriptAlias /nagiosgraph/cgi-bin "/usr/local/nagiosgraph/cgi"

ScriptAlias /nagiosgraph/cgi-bin "/usr/local/nagiosgraph/cgi"
Alias /nagiosgraph "/usr/local/nagiosgraph/share"

希望这可以帮助

相关内容