Recommended tutorial: linux tutorial
First, an IP binding Multiple domain names are very common. Most of the rented virtual hosts have multiple hosts sharing the same IP. To distinguish which host is being accessed, two aspects must be implemented:
1. How does the client distinguish between different websites?
When the client makes a request, it will include the specific host name to be requested in the HTTP request. For example, the request to access Google passes The packet capture analysis content is as follows:
GET / HTTP/1.1 Host: www.google.com
The entire request will be sent to the server, and there is a Host field identifying the domain name of the website you want to request. Even if the access is to the same IP address, due to the Host field Different, so the server software has a way to distinguish which website is being visited.
For the specific definition of the Host field, you can read Section 14.23 of RFC-2616: http://www.rfc-editor.org/rfc/rfc2616.txt
The following is an excerpt ( Note the bold part):
14.23 Host
The Host request-header field specifies the Internet host and port
number of the resource being requested, as obtained from the original
URI given by the user or referring resource (generally an HTTP URL,
as described in section 3.2.2). The Host field value MUST represent
the naming authority of the origin server or gateway given by the
original URL. This allows the origin server or gateway to
differentiate between internally-ambiguous URLs, such as the root "/"
URL of a server for multiple host names on a single IP address.
In addition, RFC-2616 is not the latest specification of the HTTP protocol. For specific specifications, please refer to the description link of RFC-2616: Information on RFC 2616
##2. How to configure the server side
If the server uses Apache, then add VirtualHost to the Apache configuration file to add a new virtual host:<VirtualHost 10.0.0.1> ServerAdmin admin@admin DocumentRoot "D:/website1" ServerName http://myhost1.com DirectoryIndex index.php </VirtualHost> <VirtualHost 10.0.0.1> ServerAdmin admin@admin DocumentRoot "D:/website2" ServerName http://myhost2.com DirectoryIndex index.php </VirtualHost>
For IIS, IIS can use the same IP to bind multiple sites. For details, please refer to the figure below:
In Default Website->Properties->Website->Advanced, just add different domain names. Because my IIS version is lower, it cannot support binding multiple websites. In higher versions of IIS, multiple websites can be configured, and each website can be bound to a different domain name to achieve differentiation during access. If the server does not set a default website, the IP address cannot directly access the host. So, if you access the website directly through the IP address, you will encounter two situations:
1. The server sets a default website, or uses the IP as the host name to match the request Host field, then this is the website you access through IP;
2. The server does not set a default website, or the default website is banned, then you cannot open anything through IP. Usually What I encountered was a 404 error (page not found). I encountered similar errors in several virtual hosting service providers I have used.
In addition, whether it is IIS or Apache or other types of website server software, it not only supports multiple domain names, but also supports multiple IPs, that is, a server has multiple domain names and multiple IP addresses at the same time. IPs do not interfere with each other.
The above is the detailed content of Can one IP address correspond to multiple domain names?. For more information, please follow other related articles on the PHP Chinese website!