【发布时间】:2019-03-13 14:55:17
【问题描述】:
我在我的 mac (high sierra) 上配置了 Apache、SQL 和 PHPMyAdmin。一切正常,只是由于某种原因我似乎无法使用我的虚拟主机地址。
以下是我为使用 vhost 而编辑的代码行:
/private/etc/apache2/extra/httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/username/Sites/
</VirtualHost>
# http://localhost/ethospractice.cms.com/web/
<VirtualHost *:80>
DocumentRoot /Users/username/Sites/ethospractice.cms.com/web/
ServerName craft3.ethospractice.test
DirectoryIndex index.php
<Directory "/Users/username/Sites/ethospractice.cms.com/web/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我在 /private/etc/apache2/httpd.conf 上取消了以下行
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
并更改 de RootDirectory 以服务于我的站点文件夹,如下所示:
DocumentRoot "/Users/username/Sites"
<Directory "/Users/username/Sites">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
然后我将它添加到我的主机文件中
127.0.0.1 localhost
127.0.0.1 craft3.ethospractice.test
当我转到craft3.ethospractice.test 时,它说无法访问该站点。 但是,如果我手动转到为该主机指定的 DocumentRoot (http://localhost/ethospractice.cms.com/web/) 目录,则该站点的服务不会出现任何问题。 我的本地主机工作正常。如果我转到 localhost,它会为我的 Sites 文件夹提供服务。
所以我不知道为什么我的虚拟主机配置不起作用。我上网两天了,还没有找到解决办法。
【问题讨论】:
-
当您转到命令行并重新启动 Apache 时,它会抛出任何错误吗?如果你只是去“本地主机”,它会显示你想要的网站吗?
-
@mrunion 它不会抛出任何错误。当我转到“本地主机”时,它会提供我的“站点”文件夹广告,因为我以这种方式配置它
标签: apache localhost vhosts hosts