Content
Definition, general meaning
A Virtual host (Virtual host or virtual hosting, in short: vhost) originally refers to the practice of running multiple websites on a single web server at the same time (e.g., website1.hu, website2.hu, etc.). Virtual hosts can be IP-based or name-based. It does not matter to the end user which IP address and / or server the site is physically accessible to.
A Virtual hosting one of the most commonly used implementations is shared web hosting. Renting a shared web host is much cheaper than a dedicated server because many clients can be served by a single server. It is also very common to use multiple names on a single site on the same machine at the same time to better reflect the services offered.
Virtual host types
IP-based
For IP-based hosts, separately for each site / hostname IP address which are directly accessible by any protocol but all served domain name a dedicated IP address is required. Thus, the domain names of these sites all point to separate IP addresses on the same server. In this case, the web server is equipped with multiple physical network interfaces or is configured with multiple virtual network interfaces on the same physical interface. The web server can open multiple at once socketyou can also monitor each IP address separately, or listen to all interfaces at once with a single open socket. In the latter case, after the TCP connection is accepted, it obtains the IP address from which it was received. Either way, you use the IP address to determine which site to serve. The client is not involved in this process, so there are no compatibility issues, unlike name-based virtual hosting.
The disadvantage of this approach is that each site requires a separate IP address, which increases the administrative burden (both assigning addresses to servers and verifying the use of addresses by Internet registrars) and speeds up the process of depleting IPv4 addresses.
name-based
With name-based virtual hosts, websites with multiple domain names can connect to the same IP address on the server. These names are determined by the customers. This method saves many IP addresses and the administrative burden associated with them, but there are difficulties with name-based virtual hosting. SSL / TLS .
A technical prerequisite for name-based virtual hosts is a web browser with HTTP / 1.1 support that includes the destination name in the request. This allows you to serve the right content from multiple sites running behind a single IP address on a server. More specifically, this means that the hostname must be sent in the request HTTP header, which is already mandatory in the HTTP / 1.1 standard.
For example, a server can receive requests for two domains: www.example.com and www.example.com. Both names are routed to the same IP address. When retrieving www.example.com, the server must release the requested files from the / home / user1 / public_html / directory, while in the case of www.example.com, the server provides the content from the / home / user2 / public_html / directory. Similarly, the contents of multiple subdomains of a domain name can be stored together. For example, a blog server can host blog1.domain.hu and blog2.domain.hu.
A big problem with name-based virtual hosting is that it is difficult to manage multiple secure sites that use SSL / TLS. Because the SSL / TLS handshake occurs before the hostname is sent, the server does not know which certificate to use in the handshake procedure. It is possible for a single certificate to cover multiple names either in the "subjectaltname" field or even by wildcards, but the practical application of this approach is limited by administrative considerations and wildcard substitution rules. A solution to this is a TLS extension, Server Name Indication (SNI), which is designed to provide the correct hostname at the beginning of the SSL / TLS handshake process to avoid this problem. However, some older browser clients, such as older Internet Explorer running on XP or older versions of Android, do not support this.
Also, if the Domain Name System (DNS) service does not work properly, accessing a Web site running on virtual hosting is difficult even if the IP address is known. For example, if the DNS server is down, the user is trying to get the IP address of the website directly in their browser, e.g. http://100.100.100.100/, the web browser sends the IP address as a hostname to the server. And because the web server relies on the HTTP header of the browser request to determine which vhost to retrieve, the server cannot find the right virtual storage and returns to the default web page, which in most cases is different from what the user expects.
In this case, the solution is to add the IP address and hostname of the website to the hosts file on the client system. At this point, accessing the desired website through the domain name will work again. In this case, however, the user must be careful because the real relationships between IP addresses and hostnames are overwritten by modifying the hosts file on the local machine. Therefore, this solution is not really recommended for the average user, but can be useful for an administrator, for example, while repairing bad DNS records.
Combined
IP-based and name-based virtual hosts can be combined: the server can have multiple IP addresses, and each server can host multiple name-based websites at the same time. This technique can be useful if you have a website on your server wildcard type SSL / TLS is used. For example, if an operator also has two wildcard certificates, one for * .example.com and the other for * .example.com, the server can be served from an IP address to something.example.com and also something.example.com, but you may need a separate IP address to serve something1.example.com.
Apache web server
Az Apache HTTP server was one of the first web servers to support IP-based virtual hosting. As of version 1.1, it supports both types, ie both IP-based and vhost virtual hosts.
Apache virtual host file settings are used to select server requests for the appropriate web page. These files have their own syntax, let's see some examples
IP based virtual host example
In the following example, the server has two IP addresses (172.20.30.40 and 172.20.30.50) that are associated with www.example1.com and www.example2.com:
Listen 80
<VirtualHost 172.20.30.40>
DocumentRoot "/home/felhasznalo1/public_html"
ServerName www.pelda1.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot "/home/felhasznalo2/public_html"
ServerName www.pelda2.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
Name-based virtual host example
In this example, the server has two hostnames (www.example1.hu and www.example2.hu) that are associated with the same IP address, and you want the server to respond differently to requests for the two domain names.
Listen 80
<VirtualHost *:80>
DocumentRoot "/home/felhasznalo1/public_html"
ServerName www.pelda1.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/home/felhasznalo2/public_html"
ServerName www.pelda2.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
Combined virtual host example
Here's a combination of the previous two: Two IP-based virtual hosts on separate IP addresses (172.20.30.40 and 172.20.30.50), and a third IP address (172.20.30.60) on two name-based virtual hosts (www.example3.com and www.example4). en)
Listen 80
# IP-alapú virtualhosztok eltérő szerver IP-címeken
<VirtualHost 172.20.30.40>
DocumentRoot "/home/felhasznalo1/public_html"
ServerName www.pelda1.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot "/home/felhasznalo2/public_html"
ServerName www.pelda2.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
# Névalapú virtualhosztok ugyanazon a szerver IP-címen
<VirtualHost 172.20.30.60>
DocumentRoot "/home/felhasznalo3/public_html"
ServerName www.pelda3.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
<VirtualHost 172.20.30.60>
DocumentRoot "/home/felhasznalo4/public_html"
ServerName www.pelda4.hu
# További kapcsolók jöhetnek ide
</VirtualHost>
- 818 views