How the virtual host is configured

Source: Internet
Author: User

Why use a virtual host?

We should know that in order to access a Web site, the premise is on an operating system, that is, the physical host. Second, the need for host, IP, and server. Because it is so wasteful to maintain a site, we expect to be able to virtualize multiple simultaneous sites (or hosts) on a single physical host, introducing a virtual host.

There are three ways we can define different virtual hosts:

Based on IP--> ip1:80, ip2:80

Based on port--> ip:80, ip:8080

Multiple different host names using the same IP based on the domain name-->

Below we configure each of the three ways to implement the virtual host:

First, close the central host, and open port 8080.

Edit/etc/httpd/conf/httpd.conf

More Wonderful content: http://www.bianceng.cn/Servers/web/

Second, in the/etc//httpd/conf.d/directory, create a virtual.conf file (also can be the configuration of the virtual host directly into the main configuration file)

Edit its contents, as follows

Namevirtualhost 172.16.13.2:80 # Enables virtual hosts based on different host names <virtualhost 172.16.13.1:80> # Virtual host-defined containers ServerName WWW.A.O RG # define host name DocumentRoot "/var/www/a.org" # define the directory where the site resource resides Customlog/var/log/httpd/a.org/error_log combined # definition is wrong  
  Error log information directory </VirtualHost> <virtualhost 172.16.13.2:80> # Set Default virtual host, that is, open this IP into the default page ServerName _default_ DocumentRoot "/var/www/default" </VirtualHost> <virtualhost 172.16.13.2:80> ServerName www.b.org D Ocumentroot "/var/www/b.org" Customlog/var/log/httpd/b.org/error_log combined <directory "/var/www/b.org>" Define the work attributes of the site Resource directory Options None # defines the access properties of a Web page file in the directory that is accessed allowoverride Authconfig # Defines the authentication information that the user accesses (in the previous article we have detailed
        Fine description) AuthType basic AuthName "Restric area." AuthUserFile "/ETC/HTTPD/.HTPASSWD" # Here you need to generate. htpasswd user files Require valid-user </Directory> </virt ualhost> <virtualhost 172.16.13.2:80> ServerName www.c.org  
  DocumentRoot "/var/www/c.org" Customlog/var/log/httpd/c.org/error_log combined <directory "/VAR/WWW/C.ORG&G"  
        T Options none allowoverride None order Allow,deny allow to all </Directory> &L T;/virtualhost> <virtualhost 172.16.13.1:8080> # authentication based on different ports ServerName www.d.org documentroot "/var/www /d.org "Customlog/var/log/httpd/d.org/error_log combined </VirtualHost>

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.