localhost不会想要VirtualHost

时间:2010-04-28 01:19:29

标签: apache2 ip-address localhost virtualhost

我的计算机上安装了几个VirtalHosts。我想使用my comp的IP地址从不同的PC上访问我正在使用的网站,但是我尝试过的每个配置都会将我带到另一个虚拟主机(实际上是我设置的第一个虚拟主机)我的比赛)。如何设置apache virtualhost配置以确保ip地址将我带到我想要的站点。

/etc/apache2/sites-available/site-i-want-to-show-up-with-ip-address.conf包含:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

ServerAlias currentsite.com

DocumentRoot /path/to/root/of/site-i-want-to-show-up
ServerName localhost

ScriptAlias /awstats/ /usr/lib/cgi-bin/

CustomLog /var/log/apache2/current-site-access.log combined
</VirtualHost>

/etc/apache2/sites-available/site-that-keeps-showing-up.conf包含:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerAlias theothersite.com
    DocumentRoot /path/to/it
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

</VirtualHost>

我很感激任何人的帮助。

另外,我对配置Web服务器的了解不多,我使用教程来获取上述代码。

3 个答案:

答案 0 :(得分:2)

Apache 2.x Virtual Hosts

1)您需要在VirtualHosts部分之前使用此功能:

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

2)每个部分都需要一个DocumentRoot和一个ServerName项:

<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com

# Other directives here ...

</VirtualHost>

答案 1 :(得分:1)

确保named virtual hosts已开启。然后从另一台计算机上,您需要设置hosts文件,以便在访问这两个域时它将转到服务器的IP。

ip.addr.x.y currentsize.com
ip.addr.x.y theothersite.com
# ip.addr.x.y is the ip of the pc with apache, this file goes on your other pc

如果您想通过IP地址访问,则无法使用基于名称的虚拟主机,为此,您需要多个IP并将每个虚拟主机设置为每个IP,例如

<VirtualHost ip.addr.x.y:80>
# one of the two IP addresses bound to the pc with apache on it
</VirtualHost>

<VirtualHost ip.addr.x.z:80>
# the other of the two IP addresses bound to the pc with apache on it
</VirtualHost>

如果请求未指定名称,则使用第一个配置的命名虚拟主机。

答案 2 :(得分:0)

在/ etc / hosts中添加一个:

127.0.0.1 theothersite.com
相关问题