apache虚拟主机

查看:120
本文介绍了apache虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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

其中一个的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这个项目?就是这里搞不懂。。。。请大神搭救搭救。。。。。。

解决方案

官方文档在此: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的配置。

这篇关于apache虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆