本地主机无法连接到所需的虚拟主机

发布于 2024-08-30 17:03:55 字数 959 浏览 7 评论 0原文

我的计算机上设置了多个 VirtalHost。我想使用我的电脑的 IP 地址从另一台 PC 访问我当前正在工作的网站,但我尝试过的每个配置都会将我带到不同的虚拟主机(实际上是我设置的第一个虚拟主机)我的补偿)。如何设置 apache 虚拟主机配置以确保 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服务器不太了解,我使用教程来获取上述代码。

I have several VirtalHosts set up on my computer. I'd like to visit the site I'm currently working on from a different PC using the my comp's ip address, but every config i've tried keeps taking me to a different virtual host (in fact the first virtualhost I set up on my comp). How do I set up the apache virtualhost configs to ensure that the ip address takes me to the site I want it to.

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

<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>

And /etc/apache2/sites-available/site-that-keeps-showing-up.conf contains:

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

</VirtualHost>

I'd appreciate anyone's help.

Also, I don't know too much about configuring web servers, and I used tutorials to get the above code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

他是夢罘是命 2024-09-06 17:03:55

Apache 2.x 虚拟主机

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>

Apache 2.x Virtual Hosts

1) You need this prior to your VirtualHosts sections:

# Ensure that Apache listens on port 80
Listen 80

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

2) Each section needs a DocumentRoot and a ServerName item:

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

# Other directives here ...

</VirtualHost>
美人骨 2024-09-06 17:03:55

确保命名虚拟主机已开启。然后,从另一台计算机上,您需要设置主机文件,以便在访问这两个域时它将转到服务器的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>

如果请求未指定名称,则它使用首先配置命名虚拟主机。

Make sure named virtual hosts are on. Then from the other computer, you need to set the hosts file so that it will go to the IP of the server when those two domains are accessed.

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

You can't use name based virtual hosts if you want to access via IP address, to do that you'd need multiple IP's and set each virtual host to each IP, like

<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>

If the request doesn't specify a name, it uses the first configured named virtual host.

自由范儿 2024-09-06 17:03:55

在 /etc/hosts 中也添加一个:

127.0.0.1 theothersite.com

add one in /etc/hosts too :

127.0.0.1 theothersite.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文