ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Web Technologies
    EC-331
    Progress0 / 38 topics
    Topics
    1. Introduction to Web Applications2. TCP/IP Application Services3. Web Servers: Basic Operation4. Web Servers: Virtual Hosting5. Web Servers: Chunked Transfers6. Web Servers: Caching Support7. Web Servers: Extensibility8. SGML9. HTML510. CSS311. XML Languages and Applications: Core XML12. XML Languages and Applications: XHTML13. XML Languages and Applications: XHTML MP14. Web Service: SOAP15. Web Service: REST16. Web Service: WML17. Web Service: XSL18. Web Services: Operations19. Web Services: Processing HTTP Requests20. Web Services: Processing HTTP Responses21. Web Services: Cookie Coordination22. Web Services: Privacy and P3P23. Web Services: Complex HTTP Interactions24. Web Services: Dynamic Content Delivery25. Server Configuration26. Server Security27. Web Browsers Architecture and Processes28. Active Browser Pages: JavaScript29. Active Browser Pages: DHTML30. Active Browser Pages: AJAX31. JSON32. Approaches to Web Application Development33. Programming in Any Scripting Language34. Search Technologies35. Search Engine Optimization36. XML Query Language37. Semantic Web38. Future Web Application Framework
    EC-331›Web Servers: Virtual Hosting
    Web TechnologiesTopic 4 of 38

    Web Servers: Virtual Hosting

    6 minread
    1,093words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time6 min
      Word count1,093
      Code examples0
      DifficultyIntermediate