在apache中定义VirtualHosts失败

时间:2012-08-14 11:38:47

标签: apache apache2

我尝试在apache中使用vhost文件( httpd-vhosts.conf )来为不同的域名定义不同的目录。我将其定义为以下并重新启动apache。

没有成功 - 当我尝试访问 www.domain.mx 时,它并没有带我走到文档中提到的路径。

我确保vhost文件包含在 httpd.conf 文件中并且已加载其模块。

我做错了什么?

NameVirtualHost 12.12.65.90:80
NameVirtualHost domain.mx:80
NameVirtualHost www.domain.mx:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost 12.12.65.90:80>
    ServerAdmin webmaster@23.21.65.90
    DocumentRoot "C:/xampp/htdocs/"
    ServerName 12.12.65.90
    ServerAlias http://12.12.65.90/
    ErrorLog "logs/general-errors.log"
    CustomLog "logs/general.log" combined
</VirtualHost>

<VirtualHost domain.mx:80>
    ServerAdmin webmaster@domain.mx
    DocumentRoot "/taska/"
    ServerName domain.mx
    ServerAlias domain.mx
    ErrorLog "logs/domain-errors.log"
    CustomLog "logs/domain.log" combined
</VirtualHost>


<VirtualHost www.domain.mx:80>
    ServerAdmin webmaster@domain.mx
    DocumentRoot "/taska/"
    ServerName www.domain.mx
    ServerAlias www.domain.mx
    ErrorLog "logs/domain-errors.log"
    CustomLog "logs/domain.log" combined
</VirtualHost>

1 个答案:

答案 0 :(得分:2)

显然这是实现它的方法(使用serverAlias):

NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@domain.mx
    DocumentRoot "c:/xampp/htdocs/taska"
    DirectoryIndex taska.html
    ServerName domain.mx
    ServerAlias domain.mx
    ErrorLog "logs/domain-errors.log"
    CustomLog "logs/domain.log" combined
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin webmaster@domain.com
    DocumentRoot "c:/xampp/htdocs/taska"
    DirectoryIndex taska.html
    ServerName www.domain.mx
    ServerAlias *.domain.mx
    ErrorLog "logs/domain-errors.log"
    CustomLog "logs/domain.log" combined
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@21.11.65.90
    DocumentRoot "c:/xampp/htdocs/"
    ServerName localhost
    ServerAlias 21.11.65.90
    ErrorLog "logs/general-errors.log"
    CustomLog "logs/general.log" combined
</VirtualHost>

<Directory C:/xampp/htdocs/taska>
  Order Deny,Allow
  Allow from all
</Directory>