Apache:两个主机指向相同的域

时间:2017-07-24 14:12:25

标签: php apache virtualhost

我有两个网站在两个独立的文档根目录下托管在同一个服务器中。现在,两个站点的URL已在域级别中更改(这由第三方完成)。现在,问题似乎是两个URL都链接到同一个网站。问题出在哪里?

这就是虚拟主机所说的:

NameVirtualHost 123.123.123.124:80
<VirtualHost 123.123.123.124:80>  
    ServerName www.test.com
        DocumentRoot "/path/to/document/root/"
      <Directory "/path/to/document/root/">
      php_admin_flag engine on
      Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
DirectoryIndex index.html index.php
    </Directory>
</VirtualHost>

NameVirtualHost 123.123.123.124:80
<VirtualHost 1123.123.123.124:80>  
    ServerName www.test2.com
    DocumentRoot "/path/to/document/root/"
      <Directory "/path/to/document/root/">
        php_admin_flag engine on
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
DirectoryIndex index.html index.php
</Directory>
</VirtualHost>

1 个答案:

答案 0 :(得分:0)

我没有正确的想法导致问题的原因。但如果您为虚拟主机配置此配置会发生什么:

# try it with the asterisks in front of :80
# are you shure 123.123.123.124 is the ip you need?
NameVirtualHost *:80

# setup for test.com
<VirtualHost *:80>
    ServerName www.test.com
    DocumentRoot /path/to/document/test/
</VirtualHost>

<Directory "/path/to/document/test/">
    php_admin_flag engine on
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    DirectoryIndex index.html index.php
</Directory>

# setup for test2.com
<VirtualHost *:80>
    ServerName www.test2.com
    DocumentRoot /path/to/document/test2/
</VirtualHost>

<Directory "/path/to/document/test2/">
    php_admin_flag engine on
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    DirectoryIndex index.html index.php
</Directory>

如果您对vhost配置进行了更改,请不要忘记重新启动apache服务器!

# macintosh
sudo apachectl restart

# linux
sudo service apache2 restart

# windows
# sorry i do not know :D