0

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

虚拟主机 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>

和虚拟主机 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 时,它会显示“temp”网站(这就是我想要的),但是当我想要访问“myNEWsite”时,http://123.123.123.123/它仍然会显示“temp”网站。

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

4

1 回答 1

0

您可以创建一个虚拟网络接口并将另一个 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>

查看此站点以获取有关虚拟主机配置的更多信息。

ps:添加了一些关于虚拟网络设备的提示。

于 2013-08-16T10:07:16.480 回答