Web website service 2.2

2.2. Build a virtual web host

  • A virtual web host refers to running multiple web sites on the same server. Each site does not actually occupy the entire server independently, so it is called a "virtual" web host.
  • Virtual host types supported by httpd:
    • Based on domain name: Use a different domain name for each virtual host, but the corresponding IP address is the same.
    • Based on IP address: Use a different domain name for each virtual host, and the IP limbs are also different. This method requires multiple network interfaces for the server and is not widely used.
    • Port-based: IP addresses and domain names are not used to distinguish different site contents. Different TCP port numbers are used, so users need to specify port numbers when browsing virtual sites of different i.
    • Note: Because different types of virtual hosts have different differentiation mechanisms, it is recommended not to use them at the same time, otherwise they will be confused with each other.
  • 2.2.1 Domain name-based virtual host
    • 1. Provide domain name resolution for virtual hosts
      • First, you need to register the domain name of the virtual Web site with the DNS service provider, so that when you access any of the virtual Web sites, you end up visiting the same IP address) - the IP address of the server that actually supports all virtual Web sites.
    • Exercise: Resolve two virtual web hosts www.accp.com and www.benet.com to the same IP address - 173.17.17.11
    • Build your own DNS server, add two areas www.accp.com and www.benet.com to the main configuration file named.conf ; set the A record of "www——"173.17.17.11" in the area data file of each area, confirm The client can resolve the IP addresses corresponding to www.accp.com and www.benet.com ;
    • For example: build bind service in the server with IP address 173.17.17.2, the configuration reference is as follows:

    • 2. Prepare web documents for the virtual host
    • Prepare the website directory and web page documents for each virtual web host. For the convenience of testing, provide each virtual web host with a home page file containing different contents.

      • 3. Add virtual host configuration
      • To enable a domain name-based virtual web host, you need to configure the following aspects:
        • Virtual host area: Use <VortualHost listening address> and omit the </VirtualHost> area configuration here to create independent configuration content for each virtual Web host. At least include the name of the virtual host and configuration items of the web page root directory; management mailboxes and access logs are added according to the actual situation.
        • Directory permissions: Use <VirtuallHost listening address> and omit </VirtuallHost> zone configuration to set access permissions for the website directory of each virtual web host, such as allowing anyone to access
        • Note: When there are a large number of virtual Web hosts, it is recommended to use an independent virtual host configuration file, and then load these configuration items through Include in the httpd.conf file, which facilitates maintenance.

          • 4. Access the virtual web host on the client computer
            • In the browser, use the website name to access different virtual web hosts and you can see different web page content, which is successful. If you cannot see the results, you need to check the homepage files of the two sites.
  • 2.2.2 IP address-based, port-based virtual host
    • Similar to domain name-based virtual hosts, you need to provide domain name resolution, web page documents, httpd configuration, restart httpd, and test
    • Difference: Different types of virtual hosts have different configuration contents in the httpd.conf file.
      • 1. IP-based virtual hosting
      • Each virtual Web host uses a different IP address to provide external Web browsing services through an httpd. It requires the use of a large number of network interfaces, which is not convenient in practice and is not widely used.

            • 2. Port-based virtual host
              • Port-based virtual hosting is only used for one Web site, targeting the same IP and website name. For example http://www. bdqn.com : 8353
              • For a port-based virtual host, you need to specify the listening port number through multiple Listens. The IP and port should be specified at the same time in VirtualHost.
              • For example: when accessing www.bdqn.com through port 80 , you will see the normal bdqn site content. When accessed through port 8353, you can see the background management system interface; refer to the following content to adjust the configuration of the httpd server

Guess you like

Origin blog.csdn.net/m0_65487180/article/details/129896100