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
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. . . . . .
The official document is here: An In-Depth Discussion of Virtual Host Matching
You belong to "Name-based vhost", just read this paragraph:
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 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 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.
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