hôte virtuel Apache
伊谢尔伦
伊谢尔伦 2017-05-16 16:57:58
0
3
752

Je recherchais récemment des hôtes virtuels, puis j'ai configuré deux hôtes virtuels comme suit

L'un d'eux a ServerName défini sur 127.0.0.1. Ajoutez ensuite

au fichier hosts sur le lecteur C

Puis la question se pose.
Lorsque je saisis directement www.abc.com dans le navigateur, j'accéderai au projet E:/wamp/crm Pourquoi ? www.abc.com ne correspond-il pas à 127.0.0.1 dans les hôtes ? Ne devrait-il pas être accessible par E:/wamp/wamp/www ? Puis lorsque je saisis directement 127.0.0.1 dans le navigateur, j'accède au projet E:/wamp/wamp/www? Je ne comprends tout simplement pas ici. . . . S'il te plaît, aide-moi, mon Dieu. . . . . .

伊谢尔伦
伊谢尔伦

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

répondre à tous (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端口访问第二个

        Derniers téléchargements
        Plus>
        effets Web
        Code source du site Web
        Matériel du site Web
        Modèle frontal
        À propos de nous Clause de non-responsabilité Sitemap
        Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!