apache虚拟主机
伊谢尔伦
伊谢尔伦 2017-05-16 16:57:58
0
3
882

最近在研究虚拟主机,然后我配置了两个虚拟主机,如下

其中一个的ServerName设置为127.0.0.1 。然后再C盘的hosts文件里面增加

那么问题来了。
我在浏览器直接输入www.abc.com时候会访问到E:/wamp/crm这个项目,为什么呢?在hosts里面www.abc.com不是对应127.0.0.1吗,不是应该访问E:/wamp/wamp/www这个项目吗?然后我在浏览器直接输入127.0.0.1的时候访问的是E:/wamp/wamp/www这个项目?就是这里搞不懂。。。。请大神搭救搭救。。。。。。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(3)
洪涛

官方文档在此:An In-Depth Discussion of Virtual Host Matching

你这个属于“Name-based vhost”,就看这一段好了:

If there are multiple VirtualHost directives listing the IP address
and port combination that was determined to be the best match, the
"list" in the remaining steps refers to the list of vhosts that
matched, in the order they were in the configuration file.

我来简单翻译,在vhost IP和端口吻合的情况下(就是你这里的*:80),apache会根据vhost配置文件中vhost的先后顺序依次进行匹配.

If the connection is using SSL, the server supports Server Name
Indication, and the SSL client handshake includes the TLS extension
with the requested hostname, then that hostname is used below just
like the Host: header would be used on a non-SSL connection.
Otherwise, the first name-based vhost whose address matched is used
for SSL connections. This is significant because the vhost determines
which certificate the server will use for the connection.

如果是SSL连接,会根据TLS握手信息里面的SNI寻找主机名。如果不支持SNI,就匹配给第一个IP和端口(这里指的还是 *:80)吻合的vhost.

If the request contains a Host: header field, the list is searched for
the first vhost with a matching ServerName or ServerAlias, and the
request is served from that vhost. A Host: header field can contain a
port number, but Apache always ignores it and matches against the real
port to which the client sent the request.

如果HTTP头部有Host信息,则匹配给第一个和ServerName或者ServerAlias吻合的虚拟主机。有的时候Host会包含端口信息,Apache不会鸟这个端口。

The first vhost in the config file with the specified IP address has the highest priority and catches any request to an unknown server name, or a request without a Host: header field (such as a HTTP/1.0 request).

如果都没匹配上,扔给第一个IP端口(指的还是你的那个*:80)吻合的vhost

你访问的abc.com是第一个crm那个么?不是, 是127.0.0.1么(只有地址栏直接输入127.0.0.1才算)? 不是,那就走默认的,也就是第一个crm的配置。

过去多啦不再A梦

个人感觉serverName没啥用,所以你这个按优先适配原则,按80端口就直接是第一条规则。你要真想挂俩站点,用端口号区分就好了~
另外也可以看看文档。中文文档推荐译者:金步国的。

大家讲道理

域名是用来解析为IP的,所以两个都是127.0.0.1
而你的两个端口同样是80,只能访问第一个了

你把下面的的改为8080,用8080端口访问第二个

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板