https://youtu.be/MmMEbLCt_-c?si=lB3tcuN_ZK7WLXri
Once the DNS directs traffic to the correct server, the web server configuration determines how incoming requests are handled. Web servers like Apache, Nginx, or IIS host multiple websites or applications on a single server through virtual hosting, allowing them to differentiate between domains, subdomains, or separate websites with distinct content.
At the core of virtual hosting is the ability to distinguish between multiple websites sharing the same IP address by leveraging the HTTP Host header.
blog.example.com). They typically have their own DNS records pointing to either the same IP address as the main domain or a different one, used to organize different sections of a website.Note: If a virtual host lacks a DNS record, it can still be accessed by modifying the local
/etc/hosts(or Windows equivalent) file to manually map the domain name to an IP address.
Virtual hosts can be configured to use completely different domains. For example, in Apache:
Apache
# Example of name-based virtual host configuration in Apache
<VirtualHost *:80>
ServerName www.example1.com
DocumentRoot /var/www/example1
</VirtualHost>
<VirtualHost *:80>
ServerName www.example2.org
DocumentRoot /var/www/example2
</VirtualHost>
<VirtualHost *:80>
ServerName www.another-example.net
DocumentRoot /var/www/another-example
</VirtualHost>
The Host header functions as a switch, enabling the web server to dynamically determine which website to serve.
Host header.Host header, and consults its configuration to find a matching entry.Host header. It is the most common, flexible, and cost-effective method as it uses a single IP address. However, it requires the web server to support name-based virtual hosting and can have limitations with certain protocols like SSL/TLS.