Apache 2.4忽略httpd-vhosts.conf文件

时间:2017-03-07 18:52:43

标签: windows apache virtualhost apache2.4

我一直按照以下步骤setup apache virtualhost (windows)在Windows中创建虚拟主机,但我不知道出了什么问题,因为它不起作用。

我想要一个带有此网址的虚拟主机:http://local.shop

的httpd-vhosts.conf

<VirtualHost *:80>    
DocumentRoot "C:/Apache24/htdocs/"
ServerName localhost
ServerAlias localhost
<Directory "C:/Apache24/htdocs/">
    AllowOverride All
</Directory>

<VirtualHost *:80>    
    DocumentRoot "C:/Apache24/htdocs/shop/"
    ServerName local.shop
    ServerAlias local.shop
    <Directory "C:/Apache24/htdocs/shop/">
        AllowOverride All
    </Directory>
    ErrorLog "logs/localhost.html-error.log"
    CustomLog "logs/localhost.html-access.log" common
</VirtualHost>

主机

    127.0.0.1   localhost
    127.0.0.1   local.shop

如果我尝试访问http://localhost,则提供的页面是C:/ Apache24 / htdocs / shop /上的页面,但如果我尝试访问http://local.shop我已经获得了下一个错误 ERR_NAME_NOT_RESOLVED

我做错了什么?

修改1:

我已删除了ServerAlias指令,现在如果我尝试访问http://localhost,则所提供的页面是正确的页面,但如果我尝试访问http://local.shop仍然无法正常工作。我收到了同样的错误 ERR_NAME_NOT_RESOLVED

编辑2: 我用过&#34; ping&#34;从Windows命令尝试访问每个主机。我收到localhost的回复,但不是来自local.shop

enter image description here enter image description here

编辑3: 我在httpd-vhosts.conf中对localhost的定义进行了更改。我已将DocumentRoot更改为&#34; C:/ Apache24 / htdocs / shop&#34;

<VirtualHost *:80>    
    DocumentRoot "C:/Apache24/htdocs/shop"
    ServerName localhost
    ServerAlias localhost
    <Directory "C:/Apache24/htdocs/">
       AllowOverride All
    </Directory>
</VirtualHost>

我没有从商店目录中获取默认页面,而是从原始localhost获取默认页面。看起来Apache忽略了httpd-vhosts.conf文件。

1 个答案:

答案 0 :(得分:0)

Apache可能正在侦听(如果您在编辑vhosts文件后重新启动它),但没有任何指向它。您需要编辑主机文件(位于C:\ Windows \ System32 \ drivers \ etc \ hosts下)并将域“local.shop”指向IP地址127.0.0.1,以便Apache可以从那里进行拾取。您可以使用记事本编辑该文件,并使用管理员权限打开。

看起来应该是这样的:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
127.0.0.1   local.shop