Can be understood as, a server ran a number of sites, both can access Baidu and can access QQ, on the use of a httpd service, a site multiple domain names, each site is a corresponding virtual host.
httpd configuration file DocumentRoot "/usr/local/apache2.4/htdocs" Why can access to 1.php under Htdocs, just because of this documentroot this parameter defines the folder
Domain name defined by ServerName
In the Windows platform to modify the hosts, the file defines the domain name IP, you can point IP to a domain name, on win CMD test success
c:\windows\system32\drivers\etc# Copyright (c) 1993-2009 Microsoft corp.## This was a sample HOSTS file used by Microsoft T CP/IP for windows.## This file contains the mappings of IP addresses to host names. each# entry should is kept on a individual line. The IP address should# is placed in the first column followed by the corresponding host name.# the IP address and the host Name should is separated by at least one# space.## Additionally, comments (such as these) may is inserted on individual# Lines or following the machine name denoted by a ' # ' symbol.## for example:## 102.54.94.97 rhino.acme.com # so Urce server# 38.25.63.10 x.acme.com # x client host# localhost name resolution is handled within DNS itself. #1 27.0.0.1 localhost#::1 localhost192.168.212.130 www.chyuanliu.com www.chyuanliu1.com
In the httpd configuration file
ServerName www.example.com:80 only defined a domain name, the default host for Apache, that is, any domain name, as long as point to this IP, will access to this site, this site is the default host. This brings the problem, if the machine runs multiple domain names, do not want all domain names to point to this site, all need to configure a virtual host in the httpd configuration file # virtual Hosts#include conf/extra/httpd-vhosts.conf
After you open the comment, the servername and DocumentRoot in the previous httpd configuration file will be invalidated
Vhosts configuration file, each virtualhost is a virtual host, is a site, the first is the default virtual host, that is, access to IP can be accessed, regardless of any domain name resolution to this IP, will visit the first, so generally we put the default virtual host into empty.
[[email protected] htdocs]# vi/usr/local/apache2.4/conf/extra/httpd-vhosts.conf<virtualhost *:80> DocumentRoot "/data/wwwroot/abc.com" #网站根目录 ServerName abc.com #网站域名 serveralias W ww.abc.com www.123.com #网站别名 errorlog "Logs/abc.com-error_log" Customlog "Logs/abc.com-access_log" Common</vi Rtualhost><virtualhost *:80> documentroot "/data/wwwroot/111.com" ServerName 111.com serveralias Www.exa mple.com errorlog "Logs/111.com-error_log" Customlog "Logs/111.com-access_log" common</virtualhost>[[email&nb Sp;protected] htdocs]# mkdir-p/data/wwwroot/abc.com[[email protected] htdocs]# mkdir/data/wwwroot/111.com[[ Email protected] htdocs]# vim/data/wwwroot/abc.com/index.php[[email protected] htdocs]# vim/data/wwwroot /111.com/index.php[[email protected] htdocs]# vi/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost LocAlhost.localdomain localhost6 localhost6.localdomain6192.168.212.130 111.com abc.com[[email protected] htdocs] # ping abc.comping 111.com (192.168.212.130) (+) bytes of data.64 bytes from 111.com (192.168.212.130): Icmp_seq=1 ttl= time=0.070 ms^c---111.com ping statistics---3 packets transmitted, 3 received, 0% packet loss, time 2000msrtt min/avg /max/mdev = 0.051/0.058/0.070/0.008 ms[[email protected] htdocs]# Curl abc.comabc.com[[email protected] htdocs]# Curl 111.com111.com[[email protected] htdocs]# Curl 192.168.212.130abc.com# default abc.com is the default host
Linux9.6 httpd Default Virtual Host