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>