0

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

没有成功 - 当我尝试访问www.domain.mx时,它不会将我带到 documentroot 中提到的路径。

我确保 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>
4

1 回答 1

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>
于 2012-08-14T15:23:31.603 回答