【问题标题】:Apache - Can't connect to specific VHostApache - 无法连接到特定的 VHost
【发布时间】: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


【解决方案1】:

为此,您必须遵循三个步骤。

  1. 在 httpd-vhosts.conf 中添加虚拟主机代码
<VirtualHost *:80>
    ServerName craft3.ethospractice.test
    DocumentRoot "C:/xamppneww/htdocs/craft_home/craft_revision/web"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xamppneww/htdocs/craft_home/craft_revision/web">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
  1. 在 hosts 文件中提及您的服务器名称
#127.0.0.1 localhost
127.0.0.1 craft3.ethospractice.test
  1. 重启xampp

就是这样。您无需执行任何其他操作。如果您仍然没有得到,那么它一定是 xampp 设置或配置相关的问题。

【讨论】:

    猜你喜欢
    • 2017-09-08
    • 2021-06-16
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2021-06-08
    • 2016-12-25
    相关资源
    最近更新 更多