本地主机显示我在/usr/local/etc/httpd/extra/httpd-vhosts.conf中添加虚拟主机时的索引

问题描述 投票:0回答:1

我安装了带有brew的apache,并将端口8080更改为80。当我访问localhost时,这会向我显示一个页面“有效!”并且该页面位于文件名称为index.html的/usr/local/var/www目录中,但是当我在/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 /

如果我从<VirtualHost *:80>中删除块httpd-vhosts.conf的代码,则localhost主机再次显示正确的index.html

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

任何帮助将不胜感激!

macos apache localhost webserver virtualhost
1个回答
0
投票

我已经解决了这个问题,在httpd.conf文件中所做的更改很小,我们不得不提到它们将首先处理哪种类型的文件,因此我只在index.php的代码块中添加了dir_module

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

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

© www.soinside.com 2019 - 2024. All rights reserved.