Host Name-based Virtual Host-Linux Enterprise Application-Linux server application information. The following is a detailed description. Host Name-based VM
This document describes how to use a domain name-based VM.
Top
Comparison between domain name-based virtual hosts and IP-based Virtual Hosts
IP-based VM uses the connected IP address to determine the corresponding VM. In this way, you need to assign an independent IP address to each VM. The domain name-based VM is determined based on the part that identifies the host name in the HTTP header submitted by the client. With this technology, many virtual hosts can share the same IP address.
Domain name-based virtual hosts are relatively simple, because you only need to configure your DNS server to map each host name to the correct IP address, and then configure the Apache HTTP Server, so that you can identify different host names. Domain name-based servers can also alleviate the problem of insufficient IP addresses. Therefore, if you have to use an IP-based virtual host for no special reason, you 'd better use a domain name-based virtual host. In the following cases, you may want to use an IP-based Virtual Host:
* Some antique clients are not compatible with Domain Name-based virtual hosts. To be compatible with Domain Name-based virtual hosts, the client must send the "Host" header. This is required in the HTTP/1.1 specification. All old browsers that currently only Support HTTP/1.0 are added to achieve this requirement. If you want to support these old browsers and use domain name-based virtual hosts. We provide a technical solution that you can see at the end of this article.
* The inherent nature of the SSL protocol determines that a domain name-based virtual host cannot become an SSL security server.
* Some bandwidth management technologies implemented by operating systems and network devices cannot distinguish them when multiple hosts share one IP address.
Top
Use a domain name-based VM
Related module commands
To use a domain name-based virtual host, you must specify the Server IP address (and possible ports) for the host to accept the request. This can be configured using the NameVirtualHost command. If all IP addresses on the server are used, you can use "*" as the parameter of NameVirtualHost. If you want to use multiple ports (such as running SSL), you must specify a port number in the parameter, such as "*: 80 ". Note that specifying an IP address in the NameVirtualHost command does not allow the server to automatically listen to that IP address. For more information, see Chapter set the address and port used by Apache. In addition, the IP address must correspond to a network interface on the server.
The next step is to create . Parameters must be the same as those of NameVirtualHost (for example, an IP address or "*" represents all addresses ). In each Segment, there must be at least one ServerName command to specify the servo host and one DocumentRoot command to show where the host content is located in the file system.
Cancel the Mainhost)
If you want to add a virtual host to an existing web server, you must also create Define a block. The ServerName and DocumentRoot contents in this VM should be consistent with the global ServerName and DocumentRoot. The VM should also be placed at the beginning of the configuration file to assume the role of the default host.
For example, assume that you are using the domain name www. domain. tld provides services, and you want to add a name named www on the same IP address. otherdomain. tld Vm, you only need. add the following content to conf:
Of course, you can replace NameVirtualHost and The "*" number in the command for some specific purposes. For example, you may want to run a domain name-based virtual host on an IP address, and run an IP address or another domain name-based virtual host on another IP address.
Many servers want to be accessed through more than one domain name. We can put the ServerAlias command To solve this problem. For example, the first The name listed in the ServerAlias command in the configuration section is the other names that the user can use to access the same web site:
ServerAlias domain. tld *. domain. tld
In this way, all access requests to the domain. tld will be processed by the virtual host www. domain. tld. Wildcard characters "*" and "? "Can be used for domain name matching. Of course, you can't just get a name and put it in ServerName or ServerAlias. You must first configure the name on your DNS server to establish a ing relationship with an IP address on your server.
Finally, you can put some other commands To better configure a virtual host. Most commands can be placed in these To change the virtual host configuration. If you want to know whether a specific instruction can be used in this way, see the instruction scope. Configuration commands within the scope of the main server (in all Commands outside the configuration segment) only take effect when they are not overwritten by the configuration of the virtual host.
In this way, when a request arrives, the server first checks whether it uses an IP address that matches the NameVirtualHost. If it can match, it will find each corresponding to this IP address And try to find a ServerName or ServerAlias configuration item that is the same as the requested host name. If it finds it, it will use this server. Otherwise, the first listed virtual host that matches the IP address will be used.
To sum up, the first listed virtual host acts as the default virtual host. When an IP address matches the configuration in the NameVirtualHost command, the DocumentRoot in the master server will never be used. Therefore, if you want to create a special configuration for processing requests that do not correspond to any virtual host, you just need to put the configuration in And put it at the beginning of the configuration file.
Top
Compatibility with earlier browsers
As mentioned above, Some browsers cannot send necessary data to domain name-based virtual hosts, making them unable to work normally. These browsers will receive a page (a domain name-based primary VM) from the first virtual host listed in the configuration that matches the IP address ).
What is old?
Please note that when we talk about the old ones, we do not mean they are very old. In reality, you may not be able to use these browsers. Almost all browsers now send Host headers required by domain name-based virtual hosts.
Although a little troublesome. However, you may still use the ServerPath command. The following is a configuration instance:
What are the above descriptions? It indicates that any URI starting with "/domain" will be servo of the VM www. domain. tld. This means that this page can be viewed by all browsers in the form of http://www.domain.tld/domain. The browser that can send the "Host:" header can also use http://www.domain.tld/in this form.
To achieve this purpose. You must first put a link to http://www.domain.tld/domain/on the page of your primary VM. Then, make sure that all relative links (such as "file.html" or ".. /icons/image.gif ") or contain/domain/prefix (for example:" http://www.domain.tld/domain/misc/file.html "or"/domain/misc/file.html ").
It may take some effort to do this, but following the instructions above will make sure that your page is correctly displayed for all browsers, regardless of the old and new
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.