时间:2022-09-03 13:12:01 | 来源:网站运营
时间:2022-09-03 13:12:01 来源:网站运营
首先,一个IP绑定多个域名是很常见的事情,租用的虚拟主机大多数都是多个主机共享同一个IP,区分具体访问的是哪个主机要从两个方面实现:GET / HTTP/1.1Host: www.google.com
整个请求会被发送到服务器上,其中有Host字段标识你要请求的网站域名是什么,即使访问的是同一个IP地址,由于Host字段不同,所以服务器软件有办法区分具体访问的是哪个网站。14.23 Host另外,RFC-2616并非HTTP协议的最新规范,具体的规范请参考RFC-2616的描述链接:
The Host request-header field specifies the Internet host and port
number of the resource being requested, as obtained from the original
URI given by the user or referring resource (generally an HTTP URL,
as described in section 3.2.2). The Host field value MUST represent
the naming authority of the origin server or gateway given by the
original URL. This allows the origin server or gateway to
differentiate between internally-ambiguous URLs, such as the root "/"
URL of a server for multiple host names on a single IP address.
<VirtualHost 10.0.0.1>以上就定义了两个域名http://myhost1.com和http://myhost2.com,分别在不同的根目录,通过这样的配置Apache如果收到http://myhost1.com的请求,那么就到d:/website1里寻找对应的页面,如果是http://myhost2.com的请求,那么就到d:/website2里寻找对应的页面。
ServerAdmin admin@admin
DocumentRoot "D:/website1"
ServerName http://myhost1.com
DirectoryIndex index.php
</VirtualHost>
<VirtualHost 10.0.0.1>
ServerAdmin admin@admin
DocumentRoot "D:/website2"
ServerName http://myhost2.com
DirectoryIndex index.php
</VirtualHost>