虚拟主机不提供具有相同IP地址的正确网站

时间:2013-08-16 09:52:12

标签: ubuntu virtualhost

我在同一台服务器上运行了两个虚拟主机(IP地址:123.123.123.123):

VirtualHost 1:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName 123.123.123.123

    DocumentRoot "/home/webmaster/development/myNEWsite.co.uk/user/htdocs"
    ErrorLog "/home/webmaster/development/myNEWsite.co.uk/logfiles/error_log"
    CustomLog "/home/webmaster/development/myNEWsite.co.uk/logfiles/access_log" common
    <Directory "/home/webmaster/development/myNEWsite.co.uk/user/htdocs/">
            AllowOverride   All
    </Directory>
</VirtualHost>

VirtualHost 2:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName temp.co.uk

    DocumentRoot "/home/webmaster/development/temp"
    ErrorLog "/home/webmaster/development/temp/error_log"
    CustomLog "/home/webmaster/development/temp/access_log" common
    <Directory "/home/webmaster/development/temp">
            AllowOverride   All
    </Directory>
</VirtualHost>

当我访问www.temp.co.uk时,它会显示“临时”网站(这就是我想要的),但是当我想通过转到http://123.123.123.123/来访问“myNEWsite”时,它仍会显示“临时”网站。

如何获取服务器的实际IP地址以显示我正在构建的新网站?

1 个答案:

答案 0 :(得分:0)

您可以create a virtual network interface并将另一个IP添加到第二个虚拟主机/服务器名称:

<VirtualHost 123.123.123.123:80>
    ServerAdmin webmaster@localhost
    ServerName myNEWsite

    DocumentRoot "/home/webmaster/development/myNEWsite.co.uk/user/htdocs"
    ErrorLog "/home/webmaster/development/myNEWsite.co.uk/logfiles/error_log"
    CustomLog "/home/webmaster/development/myNEWsite.co.uk/logfiles/access_log" common
    <Directory "/home/webmaster/development/myNEWsite.co.uk/user/htdocs/">
            AllowOverride   All
    </Directory>
</VirtualHost>

和......

<VirtualHost <virtual interface IP>:80>
    ServerAdmin webmaster@localhost
    ServerName temp.co.uk

    DocumentRoot "/home/webmaster/development/temp"
    ErrorLog "/home/webmaster/development/temp/error_log"
    CustomLog "/home/webmaster/development/temp/access_log" common
    <Directory "/home/webmaster/development/temp">
            AllowOverride   All
    </Directory>
</VirtualHost>

检查this site以获取有关虚拟主机配置的更多信息。

p.s。:添加了一些有关虚拟网络设备的提示。