2017-10-13 50 views
0

我想爲我的計算機上運行的apache2設置兩個虛擬主機。我在我的主機文件C:\ Windows \ System32 \ Drivers \ etc \ host中插入了www.vh1.com和www.vh2.com。我還創建了兩個文件夾,C:\ test1和C:\ test2,其中包含我希望www.vh1.com和www.vh2.com顯示的html文件。Apache VirtualHost沒有正確導向

但是,當我在瀏覽器上打開www.vh1.com和www.vh2.com時,我被重定向到本地主頁www.vh2.com,www.vh1.com向我顯示互聯網上的網頁。任何人都可以幫助解決這個錯誤?將不勝感激。下面是我的Apache的httpd.conf文件,減去註釋:

ServerRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2" 

Listen 80 

LoadModule actions_module modules/mod_actions.so 
LoadModule alias_module modules/mod_alias.so 
LoadModule asis_module modules/mod_asis.so 
LoadModule auth_basic_module modules/mod_auth_basic.so 
LoadModule authn_default_module modules/mod_authn_default.so 
LoadModule authn_file_module modules/mod_authn_file.so 
LoadModule authz_default_module modules/mod_authz_default.so 
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so 
LoadModule authz_host_module modules/mod_authz_host.so 
LoadModule authz_user_module modules/mod_authz_user.so 
LoadModule autoindex_module modules/mod_autoindex.so 
LoadModule cgi_module modules/mod_cgi.so 
LoadModule dir_module modules/mod_dir.so 
LoadModule env_module modules/mod_env.so 
LoadModule include_module modules/mod_include.so 
LoadModule isapi_module modules/mod_isapi.so 
LoadModule log_config_module modules/mod_log_config.so 
LoadModule mime_module modules/mod_mime.so 
LoadModule negotiation_module modules/mod_negotiation.so 
LoadModule setenvif_module modules/mod_setenvif.so 

<IfModule !mpm_netware_module> 
<IfModule !mpm_winnt_module> 

User daemon 
Group daemon 

</IfModule> 
</IfModule> 

ServerAdmin [email protected] 

DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs" 

<Directory /> 
    Options FollowSymLinks ExecCGI 
    AddHandler cgi-script .cgi .py 
    AllowOverride None 
    Order deny,allow 
    Deny from all 
</Directory> 

<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"> 

    Options Indexes FollowSymLinks ExecCGI 

AllowOverride AuthConfig 

    Order allow,deny 
    Allow from all 

</Directory> 

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

<FilesMatch "^\.ht"> 
    Order allow,deny 
    Deny from all 
    Satisfy All 
</FilesMatch> 

ErrorLog "logs/error.log" 

LogLevel warn 

<IfModule log_config_module> 

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 
    LogFormat "%h %l %u %t \"%r\" %>s %b" common 

    <IfModule logio_module> 
     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio 
    </IfModule> 

    CustomLog "logs/access.log" common 

</IfModule> 

<IfModule alias_module> 

    ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/" 

</IfModule> 

<IfModule cgid_module> 

</IfModule> 

<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin"> 
    AllowOverride None 
    Options None 
    Order allow,deny 
    Allow from all 
</Directory> 

DefaultType text/plain 

<IfModule mime_module> 
    TypesConfig conf/mime.types 
    AddType application/x-compress .Z 
    AddType application/x-gzip .gz .tgz 
    AddHandler cgi-script .cgi .py 
</IfModule> 

NameVirtualHost *:80 
<VirtualHost *:80> 
    DocumentRoot "c:/test1" 
    ServerName www.vh1.com 
     <Directory "c:/test1"> 
      Options All 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
     </Directory> 

</VirtualHost> 
<VirtualHost *:80> 
    DocumentRoot "c:/test2" 
    ServerName www.vh2.com 
     <Directory "c:/test2"> 
      Options All 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
     </Directory> 
</VirtualHost> 

<IfModule ssl_module> 
SSLRandomSeed startup builtin 
SSLRandomSeed connect builtin 
</IfModule> 

LoadModule php5_module "c:/php/php5apache2_2.dll" 
AddType application/x-httpd-php .php 
PHPIniDir "C:/php" 
+0

文件名應該是「主機」,而不是「主機」 –

回答

0

的情況下www.vh1.com GET是你在線,我懷疑它必須在你的主機文件中的一些錯誤。它應該解析爲localhost。

請檢查這個鏈接http://foundationphp.com/tutorials/apache_vhosts.php 我沒有辦法測試你的conf文件,因爲我只在Linux上託管。 老實說,我不知道是否需要雙引號。我會削減它們,將目錄移到VirtualHost規則之外。

+0

嗨,非常感謝您的幫助。事實上,我把「1」的拼寫錯誤記爲「l」。現在,當我訪問www.vh1.com時,在清除cookie和瀏覽歷史記錄後,它會被重定向到我的本地主機。但是,問題仍然是,由於www.vh1.com和www.vh2.com未訪問正確的目錄「c:/ test1」和「c:/ test2」,Apache中的VirtualHost代碼無法正常工作。相反,他們正在本地主機代碼中訪問我的「C:/ Program Files(x86)/ Apache Software Foundation/Apache2.2/htdocs」目錄。 – FlyGuy352