简体   繁体   English

基于名称的虚拟主机

[英]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.

相关问题 具有2个IP地址的Apache上基于名称的虚拟主机 - Name Based Virtual Hosts on Apache with 2 IP Address 从Internet访问基于名称的虚拟主机 - Accessing name-based virtual hosts from the internet Apache上基于端口的虚拟主机 - Port based virtual hosts on apache 基于IP和域的虚拟主机 - IP and Domain Based Virtual Hosts Apache2多个基于名称的虚拟主机在一台带有rails / rack的机器上 - Apache2 multiple name-based virtual hosts on one machine with rails/rack 基于名称的虚拟主机在OS X 10.10 Yosemite上的Apache 2.4.9中不工作/允许 - Name-based virtual hosts not working/allowed in Apache 2.4.9 on OS X 10.10 Yosemite 如何使用 3 个站点设置 Apache:两个基于名称的虚拟主机和一个通过 IP 地址 - How to set up Apache with 3 sites: Two name based virtual hosts and one via the IP address 局域网上基于apache,DNS,基于访问名称的虚拟主机,而无需在每台计算机的“主机”文件中键入IP和服务器名称 - apache, DNS, access name based virtual host on LAN without typing the IP and server name at the “hosts” file of every computer 基于名称的虚拟主机? - Name based virtual host? 如何使用相同的父服务器别名或名称在 xampp 中设置虚拟主机 - How to setup virtual hosts in xampp with same parent server alias or name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM