apache virtual host
伊谢尔伦
伊谢尔伦 2017-05-16 16:57:58
0
3
846

I was researching virtual hosts recently, and then I configured two virtual hosts, as follows

The ServerName of one of them is set to 127.0.0.1. Then add

to the hosts file on drive C.

Then the question comes.
When I directly enter www.abc.com in the browser, I will access the project E:/wamp/crm. Why? Doesn't www.abc.com correspond to 127.0.0.1 in hosts? Shouldn't it be accessed by E:/wamp/wamp/www? Then when I directly enter 127.0.0.1 in the browser, I access the project E:/wamp/wamp/www? I just don't understand here. . . . Please ask God to save me. . . . . .

伊谢尔伦
伊谢尔伦

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

reply all(3)
洪涛

The official document is here: An In-Depth Discussion of Virtual Host Matching

You belong to "Name-based vhost", just read this paragraph:

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.

Let me translate it briefly. When the vhost IP and port match (that’s *:80 here), apache will match them in sequence according to the order of vhosts in the vhost configuration file.

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.

If it is an SSL connection, the host name will be found based on the SNI in the TLS handshake information. If SNI is not supported, it will be matched to the first vhost whose IP and port (here still refers to *:80) match.

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.

If the HTTP header has Host information, it will be matched to the first virtual host that matches ServerName或者ServerAlias. Sometimes the Host will contain port information, but Apache will not read this port.

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).

If there is no match, throw it to the vhost that matches the first IP port (referring to your *:80)

Is the abc.com you visited the first crm one? No, is it 127.0.0.1 (only if you enter 127.0.0.1 directly in the address bar)? No, then use the default, which is the configuration of the first crm.

过去多啦不再A梦

Personally, I feel that serverName is useless, so according to the priority adaptation principle, port 80 is directly the first rule. If you really want to connect two sites, just use the port number to distinguish them~
You can also read the documentation. Recommended translator for Chinese documents: Jin Buguo.

大家讲道理

The domain name is used to resolve to IP, so both are 127.0.0.1
And your two ports are also 80, so you can only access the first one

You change the following one to 8080 and use port 8080 to access the second one

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template