ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3144Web Servers Virtual Ho…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3144

    Web Technologies

    Progress0 / 38 done
    Topics38
    1Introduction to Web Applications2TCP/IP Application Services
    3Basic Operation4Virtual Hosting5Chunked Transfers6Caching Support7Extensibility8SGML9HTML510CSS3
    11Core XML12XHTML13XHTML MP
    14SOAP15REST16WML17XSL
    18Operations19Processing HTTP Requests20Processing HTTP Responses21Cookie Coordination22Privacy and P3P23Complex HTTP Interactions24Dynamic Content Delivery25Server Configuration26Server Security27Web Browsers Architecture and Processes
    28JavaScript29DHTML30AJAX31JSON32Approaches to Web Application Development33Programming in Any Scripting Language34Search Technologies35Search Engine Optimization36XML Query Language37Semantic Web38Future Web Application Framework
    6 min read
    Topic 4 of 38
    Topic Study Note Illustration
    04

    Web Servers: Virtual Hosting

    Virtual hosting is a method used by web servers to host multiple websites or domain names on a single physical server. This allows multiple websites to share...

    Web Servers: Virtual Hosting

    Virtual hosting is a method used by web servers to host multiple websites or domain names on a single physical server. This allows multiple websites to share the same resources (such as the CPU, memory, and storage) while keeping their content separate. Virtual hosting is an essential feature in modern web hosting, enabling efficient use of server resources and cost savings for hosting providers and clients.

    There are two primary types of virtual hosting: name-based virtual hosting and IP-based virtual hosting. Both approaches allow a web server to serve multiple websites from the same machine but differ in how they distinguish between the websites.

    Key Concepts of Virtual Hosting

    1. Web Server Configuration:

      • A web server, like Apache or Nginx, is configured to handle requests for different domain names. By mapping domain names to specific directories on the server, it can serve the appropriate content for each website.
    2. Shared Resources:

      • All virtual hosts on a single server share the same hardware resources (e.g., CPU, memory, and storage). However, the content, configurations, and security settings for each domain are isolated, providing the illusion that each website is hosted on a separate server.
    3. Efficiency and Cost Savings:

      • Virtual hosting enables hosting providers to maximize the use of their hardware, while clients can run multiple websites without needing separate physical servers. This is particularly useful for businesses or individuals who need to host several domains but do not want to bear the cost of multiple dedicated servers.

    Types of Virtual Hosting

    1. Name-Based Virtual Hosting

    • Name-based virtual hosting (also known as DNS-based virtual hosting) is the most common form of virtual hosting. It allows a single IP address to host multiple websites by distinguishing them based on the domain name included in the request's header.

    • How it works:

      • When a browser sends a request to a web server, it includes the domain name (e.g., www.example.com) in the HTTP request. The server uses this domain name to look up the appropriate configuration for the requested website.
      • The server checks the Host header in the HTTP request, which tells it which website the client wants to access.
      • Based on the domain name, the server serves the appropriate content from the correct directory.
    • Example: Suppose a server has the following websites configured:

      • www.example1.com -> /var/www/example1/
      • www.example2.com -> /var/www/example2/

      When a request for www.example1.com comes in, the server responds with content from /var/www/example1/, and when a request for www.example2.com comes in, the server responds with content from /var/www/example2/.

    • Advantages:

      • Cost-effective: Only one IP address is needed for multiple websites, saving IP addresses and reducing costs.
      • Simpler setup: Easier to configure and manage since only the domain name needs to be used to differentiate between sites.
    • Limitations:

      • Older protocols: Name-based virtual hosting requires the HTTP/1.1 protocol or newer because the server uses the Host header to differentiate between websites. In earlier versions of HTTP, there was no Host header, so this method wouldn't work.

    2. IP-Based Virtual Hosting

    • IP-based virtual hosting involves assigning a unique IP address to each website hosted on the server. When a request is made, the server uses the destination IP address to determine which website to serve.

    • How it works:

      • Each website is configured to respond on its own IP address. For example:
        • www.example1.com might be assigned IP address 192.168.1.1.
        • www.example2.com might be assigned IP address 192.168.1.2.
      • The client’s browser sends a request to one of these IP addresses, and the server responds with the correct website’s content.
    • Advantages:

      • Better for SSL/TLS: Before the widespread use of SNI (Server Name Indication) in HTTPS, SSL certificates were tied to a specific IP address. IP-based hosting was used to serve multiple SSL-protected websites on a single server.
      • Isolation: Each website is hosted on its own IP address, offering better isolation between sites in terms of performance and security.
    • Limitations:

      • IP address consumption: Each site requires its own IP address, which is less efficient compared to name-based hosting, especially given the limited availability of IPv4 addresses.
      • More complex setup: The server needs to be configured to listen on multiple IP addresses, which can complicate the configuration.

    3. Port-Based Virtual Hosting

    • Port-based virtual hosting involves configuring different websites to respond on different ports. By default, HTTP requests are sent to port 80, and HTTPS requests are sent to port 443. With port-based hosting, websites can be configured to respond to non-standard ports (e.g., port 8080).

    • How it works:

      • Multiple websites can be served from the same IP address but distinguished by the port number. For example:
        • http://www.example1.com:8080 might point to one website.
        • http://www.example1.com:9090 might point to another.
      • The server listens for requests on different ports and directs traffic to the appropriate website based on the port.
    • Advantages:

      • This can be useful for testing or development environments where different versions of a site are running on different ports.
    • Limitations:

      • Port-based hosting is less commonly used for production environments and can be confusing for users since the port number must be explicitly included in the URL.

    Web Server Configuration for Virtual Hosting

    1. Apache Configuration (Name-Based Virtual Hosting Example):

      • Apache uses configuration files (usually httpd.conf or sites-available and sites-enabled in Linux distributions) to define virtual hosts. Here is an example configuration for two name-based virtual hosts:
      <VirtualHost *:80>
          ServerAdmin webmaster@example1.com
          DocumentRoot /var/www/example1
          ServerName www.example1.com
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
      
      <VirtualHost *:80>
          ServerAdmin webmaster@example2.com
          DocumentRoot /var/www/example2
          ServerName www.example2.com
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
      
      • This configuration tells Apache to listen for requests on port 80 and direct them to different document roots based on the ServerName specified in the HTTP request.
    2. Nginx Configuration (Name-Based Virtual Hosting Example):

      • Nginx also uses configuration files (nginx.conf) to set up virtual hosts. Here is an example:
      server {
          listen 80;
          server_name www.example1.com;
          root /var/www/example1;
      }
      
      server {
          listen 80;
          server_name www.example2.com;
          root /var/www/example2;
      }
      
      • This configuration tells Nginx to serve content from different directories based on the domain name (www.example1.com or www.example2.com).

    Conclusion

    Virtual hosting is a powerful and cost-effective way to host multiple websites on a single server. It allows for efficient use of resources while providing a unique domain name and content for each site. By configuring the web server for name-based or IP-based virtual hosting, web hosting providers can offer scalable hosting solutions. Understanding how virtual hosting works and how to configure it is essential for system administrators and web hosting providers who manage multiple websites on a single server.

    ← Previous topic 3
    Web Servers: Basic Operation
    Next topic 5 →
    Web Servers: Chunked Transfers

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    6mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Web Technologies