【问题标题】:Get Apache VHost to load index.html instead of web directory让 Apache VHost 加载 index.html 而不是 web 目录
【发布时间】:2015-06-05 08:25:31
【问题描述】:

我没有找到这个问题的答案,所以我自己问这个问题。

为了让我的 VHost 正常工作,我关注了 this answer。我的(工作)“httpd-vhosts.conf”文件看起来像这样

<VirtualHost *:80>
    ServerAdmin jesuscc1993@gmail.com
    DocumentRoot "Z:/Projects/Web/MetalTxus Site"
    ServerName metaltxus.test
    ServerAlias www.metaltxus.test
    <Directory "Z:/Projects/Web/MetalTxus Site">
        #Options FollowSymLinks
        Options Indexes FollowSymLinks
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

据我所知,我应该将“Indexes”更改为“-Indexes”,以使 Web 加载“index.html”而不是 Web 目录。

但是,当我这样做时,我的 WAMPServer 无法启动。如果我删除了“FollowSymLinks”选项,但我得到的只是一个“403 - 禁止”页面(“您无权访问此服务器上的“/”)。

由于寻找解决方案一事无成,我将其用作我的最后一个资源。

我在 Windows 8.1 中使用最新的 WampServer 版本。我想测试一个 AngularJS 应用程序。

如果您需要更多信息,请继续询问。

【问题讨论】:

    标签: angularjs apache server wamp host


    【解决方案1】:

    试试这个:-

    <VirtualHost *:80>
        ServerAdmin jesuscc1993@gmail.com
        DocumentRoot "Z:/Projects/Web/MetalTxus Site"
        ServerName metaltxus.test
        ServerAlias www.metaltxus.test
        <Directory "Z:/Projects/Web/MetalTxus Site">
            AllowOverride All
            Options Indexes FollowSymLinks
            Require all granted
        </Directory>
    </VirtualHost>
    

    Require all granted 是 Apache 2.4 语法,而您在使用时使用的是 Apache 2.2 语法

    Order deny,allow
    Allow from all
    

    现在您需要做的就是在“Z:/Projects/Web/MetalTxus Site”文件夹中放置一个名为 index.htmlindex.php 的文件。

    我建议删除文件夹名称 MetalTxus Site 中的空格,这不是绝对必要的,但它消除了另一个可能的复杂性。

    此外,如果您实际上并不打算将网站访问权限授予 The Universe,请尝试使用

    Require local
    

    如果您希望能够仅从内部网络上的其他 PC 访问该站点,请使用

    Require local
    Require ip 192.168.1  
    

    其他建议:

    还要检查 httpd.con 有没有注释掉这条线

    LoadModule dir_module modules/mod_dir.so
    

    一个有这个

    <IfModule dir_module>
        DirectoryIndex index.php index.php3 index.html index.htm
    </IfModule>
    

    【讨论】:

    • 试用:&lt;VirtualHost *:80&gt; ServerAdmin jesuscc1993@gmail.com DocumentRoot "Z:/Projects/Web/MetalTxus" ServerName metaltxus.test ServerAlias www.metaltxus.test &lt;Directory "Z:/Projects/Web/MetalTxus"&gt; AllowOverride All Options Indexes FollowSymLinks Require local &lt;/Directory&gt; &lt;/VirtualHost&gt; 它的工作原理与以前完全相同。使用Options -Indexes 仍然给我Forbidden You don't have permission to access / on this server.
    • 如果index.html 存在于正确的文件夹中,它将运行而不是列出目录。所以index.html 不是它的真名,或者它在错误的文件夹中。如果您使用记事本编辑此文件,它可能实际上称为 index.html.txt 在资源管理器中打开完整的扩展视图。
    • 它有正确的名称和扩展名。它在the online server 中运行良好。这是screenshot of what the directory on local looks like
    • 服务器上的网页是旧版本,但没有角度。重要的事实是它正在加载index.html
    • 这两个功能都启用了。
    猜你喜欢
    • 2017-03-09
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 2018-03-02
    • 1970-01-01
    相关资源
    最近更新 更多