Building a Web virtual host in a httpd server

Source: Internet
Author: User
Tags hosting web hosting

A Web virtual host is a "virtual" web host that runs multiple Web sites on the same server, each of which does not actually occupy the entire server. The virtual web hosting service can make full use of the server's hardware resources, thus greatly reducing the cost of building and running the website '
There are three types of virtual web hosts

    • Domain-based virtual host
    • IP address-based virtual host
    • Port-based virtual host
      For IP address-based virtual hosts, each virtual Web host uses a different IP address, but the Web browsing service is provided externally through the same httpd server. Because of this, the server used to support these virtual Web hosts requires a large number of network interfaces, which is expensive in practical applications, so the virtual host based on IP address is not common in the actual application, this article does not introduce, next focus on the other two kinds of virtual web host.
Building a virtual web host experiment Preparation
    • Linux virtual machine (Red Hat Enterprise 6.5) ip:192.168.175.103
    • Windows 7 Client Lab Ideas
      1. Provide domain name resolution for virtual hosting
      2. Provide Web page documentation for a virtual host
      3. Add a virtual host configuration
      4. Accessing a virtual Web host experiment in a client computer start a domain-based virtual host

        First of all, you need to properly install the httpd server software, you can choose to install RPM, or source code compiled and installed two ways.
        Add a listening address and host name to the configuration file of the HTTPD server
        Modify (/etc/httpd/conf/httpd.conf) in this configuration file while commenting out IPV6 lines

Listen 192.168.175.103:80ServerName www.localhost.com
Provide domain name resolution for virtual hosting

RPM Installing the DNS server Software

Modifying the master configuration file

Modifying a zone configuration file

Modifying a zone data configuration file


For the "accp.com" configuration file, you only need to copy "benet.com" D, note that the owner (CP-P) is reserved. The file name is also changed, otherwise it is not valid.
Start the service while using ' host ' to test if the address resolution is normal

service named starthost www.benet.com  //命令查看地址解析结果

For more detailed configuration methods for DNS refer to my previous blog: Domain name Resolution Service

Add a Web document to a virtual host

In the OPT directory, create a site for the virtual host and write a simple test page

Add a virtual host configuration

In the/etc/httpd/conf.d/directory, create a configuration file with a. conf ending, write the following

NameVirtualHost 192.168.175.103:80                                     //指定IP地址及相对应端口<VirtualHost 192.168.175.103:80>   ServerAdmin [email protected]      //管理员邮箱   DocumentRoot /opt/benet/                                                     //站点目录   ServerName www.benet.com                                                 //服务器名称   ErrorLog logs/benet.com-error_log                                      //错误日志   CustomLog logs/benet.com-access_log common                //访问日志</VirtualHost>

Based on the same port number, same IP address but different hostname, to create two configuration content at the same time under the configuration file

Accessing the virtual Web host in the client

After all configuration is complete, start the service, turn off the firewall and the SELinux firewall

service httpd startservice iptables stopsetenforce 0

Set up the network in the Windows7 virtual machine and add the DNS address

Access testing using IE browser

Port-based virtual host

and domain-based virtual host, the first installation of HTTPD Server software, modify the configuration file, because we are based on the port, so to add a new listening address, IP the same port is different.

Listen 192.168.175.103:80Listen 192.168.175.103:8080ServerName www.localhost.com
Provide domain name resolution for virtual hosting

The main configuration file modification is the same, for the zone configuration file, only need to add a "benet.com" a zone, the zone data profile can only write one.
Start the service

Add a Web document to a virtual host

Add two sites under the/OPT directory and create two home sites at the same time.

Add a virtual host configuration

Accessing the virtual Web host in the client

Start the service, turn off the firewall and SELinux firewall
Address in windows7 virtual machine, and DNS address, test with IE browser

Building a Web virtual host in a httpd server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.