【问题标题】:localhost is showing index of when I added a virtual host in /usr/local/etc/httpd/extra/httpd-vhosts.conflocalhost 显示我在 /usr/local/etc/httpd/extra/httpd-vhosts.conf 中添加虚拟主机时的索引
【发布时间】:2020-03-09 07:29:48
【问题描述】:

我用 brew 安装了 apache,并将端口 8080 更改为 80。当我访问localhost 时,这向我显示了一个页面“它有效!”该页面位于/usr/local/var/www 目录中,文件名为index.html,但是当我在/usr/local/etc/httpd/extra/httpd-vhosts.conf 文件中添加虚拟主机时。

<VirtualHost *:80>
  DocumentRoot "/Users/ranaamir/projects/sample/yii2/backend/web"
  ServerName yii2.example.be
  ServerAlias yii2.example.be
  <directory "/Users/ranaamir/projects/sample/yii2/backend/web">
      Options Indexes FollowSymLinks
      AllowOverride all
      Order Deny,Allow
      Allow from all
      Require all granted
  </directory>
  ErrorLog "/usr/local/var/log/httpd/vjfBackenderror.log"
  CustomLog "/usr/local/var/log/httpd/vjfBackendaccess.log" common
</VirtualHost>

并使用sudo apachectl -k restart 命令重新启动服务,此主机也添加到/etc/hosts

##

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
127.0.0.1       yii2.example.be

然后我访问localhostyii2.example.be 都显示一个页面,其中只有一行提到Index of /

如果我从httpd-vhosts.conf 中删除块&lt;VirtualHost *:80&gt; 的代码,那么localhost 主机再次显示正确的index.html

为什么我的项目没有在虚拟主机 url 而不是 index of / 上运行?

任何帮助将不胜感激!

【问题讨论】:

    标签: macos apache localhost webserver virtualhost


    【解决方案1】:

    我已经解决了这个问题,我在httpd.conf 文件中做了一点改动,我们必须提到它们将首先处理哪种类型的文件,所以我只是在dir_module 的代码块中添加了index.php

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

    我希望这可以节省您的时间并最大程度地减少您的压力。 :)

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 1970-01-01
      • 2015-03-25
      • 2017-12-09
      • 2013-02-25
      • 2013-04-26
      • 2014-04-25
      • 2018-04-29
      • 1970-01-01
      相关资源
      最近更新 更多