【问题标题】:Apache 2.2 VirtualHosts URL not found未找到 Apache 2.2 VirtualHosts URL
【发布时间】:2012-07-19 00:57:54
【问题描述】:

希望你能帮上忙。我有一个现有的 Apache 2.2 服务器,它为我维护的网站提供服务。我正在尝试为同事添加其他网站。这样做后,当我尝试访问 URL 时,我得到以下信息:

未找到 在此服务器上未找到请求的 URL /。

这是我的 httpd-vhosts.conf 文件的摘要。我有三个新的、大致相同的主机无法正常工作。只有 NDV 和默认值有效。

NameVirtualHost *:80

<VirtualHost anycast.ns.cs.boeing.com:80>
        ServerName anycast.ns.cs.boeing.com
        ServerAdmin aodhan.hoffman@boeing.com
        DocumentRoot "/opt/www/anycast"

        ScriptAlias /cgi-bin "/opt/www/anycast/cgi-bin/"
        ErrorLog "logs/grant_error_log"
        CustomLog "logs/grant_access_log" common
</VirtualHost>

<VirtualHost *:80>
        ServerAdmin aodhan.hoffman@boeing.com
        DocumentRoot "/opt/httpd/manual"
        ServerAlias ntpm-application-01.ns.cs.boeing.com
        ErrorLog "logs/error_log"
        CustomLog "logs/access_log" common
</VirtualHost>


<VirtualHost *:80>
        ServerAdmin aodhan.hoffman@boeing.com
        DocumentRoot "/opt/www/ndv/html"
        ServerName ndv.web.boeing.com
        ScriptAlias /cgi-bin/ "/opt/www/ndv/cgi-bin/"
        ErrorLog "logs/error_log"
        CustomLog "logs/access_log" common
</VirtualHost>

<Directory "/opt/www/ndv/html/" >
        Options Indexes FollowSymLinks Includes 
        AddType text/html .shtml
        AddOutputFilter INCLUDES .shtml 
        Order allow,deny
        Allow from all
</Directory>

<Directory "/opt/www/anycast/html/" >
        Options Indexes FollowSymLinks Includes 
        Order allow,deny
        Allow from all
</Directory>

根据上面的配置,这是服务器看到的。

$ sudo bin/apachectl -S

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server ntpm-application-01.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:30)
         port 80 namevhost ntpm-application-01.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:30)
         port 80 namevhost ndv.web.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:39)
         port 80 namevhost anycast.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:48)
         port 80 namevhost ntpget.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:60)
         port 80 namevhost dnsdig.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:70)
Syntax OK

【问题讨论】:

    标签: apache apache2 virtualhost vhosts virtual-hosts


    【解决方案1】:

    您似乎混合了配置方法:

    NameVirtualHost *:80
    
    <VirtualHost *:80>
    ServerName www.domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot /www/domain
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerName www.otherdomain.tld
    DocumentRoot /www/otherdomain
    </VirtualHost>
    

    这是 Apache Docs 中关于基于名称的 VHost 的示例。

    我可以在您的配置 VirtualHost 中看到没有 * -> anycast.ns.cs.boeing.com:80

    以及没有服务器名称的虚拟主机,例如 ServerAlias ntpm-application-01.ns.cs.boeing.com 它有一个别名,但没有名字。

    我会开始平衡示例中的配置,然后尝试 apache 是否对此更满意。

    简而言之:确保每个条目都有 *:80 和服务器名称。

    编辑:此配置未经测试,但可能适合您

    NameVirtualHost *:80
    
    <VirtualHost *:80>
            ServerName anycast.ns.cs.boeing.com
    
            ServerAdmin aodhan.hoffman@boeing.com
            DocumentRoot "/opt/www/anycast/html"
    
            ScriptAlias /cgi-bin "/opt/www/anycast/cgi-bin/"
            ErrorLog "logs/grant_error_log"
            CustomLog "logs/grant_access_log" common
    
            <Directory "/opt/www/anycast/html/" >
                Options Indexes FollowSymLinks Includes 
                Order allow,deny
                Allow from all
            </Directory>        
    </VirtualHost>
    
    <VirtualHost *:80>
            ServerName ntpm-application-01.ns.cs.boeing.com
    
            ServerAdmin aodhan.hoffman@boeing.com
            DocumentRoot "/opt/httpd/manual"
    
            ErrorLog "logs/error_log"
            CustomLog "logs/access_log" common
    </VirtualHost>
    
    
    <VirtualHost *:80>
            ServerName ndv.web.boeing.com
    
            ServerAdmin aodhan.hoffman@boeing.com
            DocumentRoot "/opt/www/ndv/html"
    
            ScriptAlias /cgi-bin/ "/opt/www/ndv/cgi-bin/"
            ErrorLog "logs/error_log"
            CustomLog "logs/access_log" common
    
            <Directory "/opt/www/ndv/html/" >
                Options Indexes FollowSymLinks Includes 
                AddType text/html .shtml
                AddOutputFilter INCLUDES .shtml 
                Order allow,deny
                Allow from all
            </Directory>
    </VirtualHost>
    

    【讨论】:

    • 谢谢,我已经平衡了配置,它现在看起来像这样,但行为没有什么不同。 ndv 仍然有效,但任播只是返回“找不到 URL”。因为我有索引,所以我希望看到一个自动索引,但它只是说'/' not found。它令人难以置信。
    • 谢谢,但行为没有什么不同。 NameVirtualHost *:80 ServerName anycast.domain.com ServerAdmin aodhan.hoffman@domain.com DocumentRoot "/opt/www/anycast" ScriptAlias /cgi-bin "/opt/www/anycast/cgi-bin/ " ErrorLog "logs/grant_error_log" CustomLog "logs/grant_access_log" common Options Indexes FollowSymLinks Includes Order allow,deny Allow from all
    • 嗯,我注意到了。引号在 apache 配置中真的有效吗?我从来没有见过。
    • 我猜引号没问题,因为你的配置对于网络服务器来说似乎没问题。我附上了一个重新格式化的,可能对你有用。请注意,您的文档根目录和directoy 指令指向不同的目录。和 ./html,我建议您将目录条目包含在 VHOST 中。
    • 还有一个额外的词:除非这件事纯粹是 Intranet:order allow,deny -> allow from all 可能是一件非常不安全的事情。
    【解决方案2】:

    我的建议是打开并阅读 apache 生成的所有日志。这将为您提供问题所在的线索。我在 Mac 上阅读了"/private/var/log/apache2/error_log" 的日志并找到了我的线索:DocumentRoot [/path/to/rootdir] does not exist.

    我打开了 vhost 文件,发现我没有用双引号将根目录封装起来,而是使用了其他看起来像双引号的字符。我用真正的双引号替换它们,重新启动apache,然后错误就消失了。

    【讨论】:

      【解决方案3】:

      对我有用的是卸载和升级(在我的情况下为 Wampserver)您正在使用的软件。

      【讨论】:

      猜你喜欢
      • 2010-11-30
      • 1970-01-01
      • 2013-05-30
      • 2014-01-26
      • 2018-07-28
      • 2011-08-08
      • 1970-01-01
      • 2011-10-01
      • 2017-04-04
      相关资源
      最近更新 更多