2017-03-07 99 views
0

我一直在遵循此步驟setup apache virtualhost (windows)在Windows中創建一個虛擬主機,但我不知道什麼是錯誤的,因爲它不起作用。Apache 2.4忽略httpd-vhosts.conf文件

我想要一個帶有此網址的虛擬主機: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:/ Apac上he24/htdocs中/店/但如果我嘗試訪問http://local.shop我已經得到了一個錯誤ERR_NAME_NOT_RESOLVED

我在做什麼錯?

編輯1:

我已刪除ServerAlias指令,現在如果我嘗試進入http://localhost服務的頁面是正確的頁面,但如果我嘗試存取權限http://local.shop仍然無法正常工作。我已經得到了同樣的錯誤ERR_NAME_NOT_RESOLVED

編輯2: 我已經使用「ping」命令從Windows,試圖達到每個主機。而我從本地主機的響應而不是從local.shop

enter image description here enter image description here

編輯3: 我已經在我的httpd-vhosts.conf本地主機的定義進行了更改。我已經改變了的DocumentRoot「C:/ Apache24/htdocs中/店」

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

而不是從商店目錄中獲取默認頁,我還是由原來的本地主機獲取默認的頁面。好像Apache忽略httpd-vhosts.conf文件。

+0

不是問題,但請刪除這些'ServerAlias'指令,他們根本沒有任何意義的方式。 – arkascha

+0

當您重新啓動http服務器時,http服務器錯誤日誌文件中的條目是什麼? – arkascha

+0

主機名「local.shop」的命令行解析嘗試產生了什麼? – arkascha

回答

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 
+0

感謝您的評論,但我仍然在我的Windows主機文件hace域local.shop。 –

+0

仍然錯誤不在Apache端,因爲實際錯誤是「ERR_NAME_NOT_RESOLVED」(即「我不知道哪個服務器是這個域)。 –