本地主机无法连接到所需的虚拟主机
我的计算机上设置了多个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Apache 2.x 虚拟主机
1) 您需要在VirtualHosts 部分:
2) 每个部分都需要一个 DocumentRoot 和一个 ServerName 项:
Apache 2.x Virtual Hosts
1) You need this prior to your VirtualHosts sections:
2) Each section needs a DocumentRoot and a ServerName item:
确保命名虚拟主机已开启。然后,从另一台计算机上,您需要设置主机文件,以便在访问这两个域时它将转到服务器的IP。
如果您想通过 IP 地址访问,则不能使用基于名称的虚拟主机,为此您需要多个 IP 并将每个虚拟主机设置为每个 IP,例如
如果请求未指定名称,则它使用首先配置命名虚拟主机。
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.
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
If the request doesn't specify a name, it uses the first configured named virtual host.
在 /etc/hosts 中也添加一个:
add one in /etc/hosts too :