[英]Name based virtual hosts
I'm having trouble figuring out how virtual hosting works. 我在弄清楚虚拟主机的工作方式时遇到了麻烦。 For example lets say in my 'hosts' file I have:
例如,在我的“主机”文件中说我有:
127.0.0.1 localhost
127.0.0.1 mysite1.com mysite1.com mysite3.com
Does this mean that whenever I type in localhost, mysite1.com, mysite2.com, or mysite3.com into my browser URL, the page loaded will be the same for all of them? 这是否意味着每当我在浏览器URL中输入localhost,mysite1.com,mysite2.com或mysite3.com时,所有页面加载的页面都是相同的?
The /etc/hosts
file only has limited connection to virtual hosting of Apache. /etc/hosts
文件仅与Apache的虚拟主机具有有限的连接。 The only thing you do with it is give your host (or rather the loop back interace lo
) several names. 您唯一要做的就是为您的主机(或者更确切地说是回环接口
lo
)取几个名字。 If you haven't set up anything about virtual hosting yet (which I assume) typing 如果您尚未设置有关虚拟主机的任何内容(我假设),请输入
http://localhost/
http://mysite1.com/
http://mysite2.com/
http://mysite3.com/
as URL in your browser will all render the same welcome page (provided you have at least set up your Apache) because in all cases the browser will try to access the web server at 127.0.0.1
which your Apache usually listens to. 因为您的浏览器中的URL都将呈现相同的欢迎页面(前提是您至少已设置了Apache),因为在所有情况下,浏览器都将尝试访问Apache通常侦听的
127.0.0.1
的Web服务器。
To create a true virtual hosting you now need to activate this feature in the configuration file of Apache using the tags 要创建真正的虚拟主机,您现在需要使用标签在Apache的配置文件中激活此功能。
<VirtualHost mysite1.com:80>
...
</VirtualHost>
<VirtualHost mysite2.com:80>
...
</VirtualHost>
<VirtualHost mysite3.com:80>
...
</VirtualHost>
The simplest version of a virtual hosting would be that you define a seperate document root for each host and share all other configuration items. 虚拟主机的最简单版本是为每个主机定义一个单独的文档根目录,并共享所有其他配置项。 The details of this (represented by the
...
), of course, would definitely be out of scope of this answer. 当然,此细节(由
...
表示)绝对不在此答案的范围内。 A good start for reading would be http://httpd.apache.org/docs/2.2/vhosts/examples.html . 阅读的一个好开始是http://httpd.apache.org/docs/2.2/vhosts/examples.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.