Introduction to Virtual Hosting
Virtual host, simply refers to a physical machine service multiple sites, each site through one or more virtual hosts to achieve
HTTP has 3 types of virtual hosts:
(1) IP-based, configuration must be configured so that the IP
(2) based on port, be sure to enable listen port this entry, open all the listening ports
(3) FQDN-based, when configured to enable the Namevirtualhost
Related configuration
Configuration Prerequisites:
The HTTPD server is already installed.
Configuration steps:
1. Port-based virtual host configuration
#vim/etc/httpd/conf/httpd.conf ... add the following content ....... Listen 8080......................<virtualhost *:80>servername www.a.comdocumentroot/vhosts/a.com/htdocs /</virtualhost> <virtualhost *:8080>servername www.b.orgdocumentroot/vhosts/b.org/ htdocs</virtualhost> # mkdir/vhosts/{a.com,b.org}/htdocs –pv[[email protected] ~]# cd /vhosts/a.com/htdocs/[[email protected] htdocs]# vimindex.html Here our port-based virtual host is configured to complete, and now in the browser enter:
http://192.168.1.11:8080/
http://192.168.1.11:80/
Observing test Results
2. FQDN -based the configuration of the virtual host
Edit the configuration file with the following details:
namevirtualhost 192.168.1.11:80 #启用NameVirtualHost This ..........< virtualhost192.168.1.11:80> servername www.a.com DocumentRoot /vhosts/a.com/htdocs/</VirtualHost> <virtualhost192.168.1.11:80> servername www.b.org DocumentRoot /vhosts/b.org/htdocs</VirtualHost>< virtualhost192.168.1.11:80> servername www.c.net documentroot /vhosts/c.net/htdocs</virtualhost> [[ Email protected] htdocs]# mkdir/vhosts/c.net/htdocs -p[[email protected] htdocs] #vim /vhosts/c.net/htdocs/index.html
FQDN -based The virtual host configuration is complete and the following access tests are performed:
[Email protected] vhosts]# curlhttp://www.c.net
[Email protected] vhosts]# curlhttp://www.b.org
[Email protected] vhosts]# curlhttp://www.a.com
-
3.< Span style= "font-weight:normal;font-size:9px;font-family: ' Times New Roman ';" > based on ip virtual host configuration
[[Email protected] vhosts] #ifconfig eth0:0 192.168.1.21[[email protected] vhosts ]# vim/etc/httpd/conf/httpd.conf...........<virtualhost192.168.1.11:80> servername www.a.com documentroot / vhosts/a.com/htdocs/</virtualhost><virtualhost192.168.1.21:80> servername www.b.org documentroot /vhosts /b.org/htdocs/</virtualhost>[[email protected] vhosts]# httpd-thttpd: could not reliablydetermine the server ' s fully qualified domain name, using 172.16.33.1 forServerNameSyntax OK[[email protected] vhosts]# !sservice httpd restartstopping httpd: &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;[&NBSP;&NBSP;OK&NBSP;&NBSP;]STARTING&NBSP;HTTPD: httpd:could not reliably determine the server ' s fully qualified domain name, using172.16.33.1 for servername [ ok &NBSP;&NBSP;]
Here we are based on The IP virtual host is configured, and the input is tested in the browser:
http://192.168.1.199/
http://192.168.1.101/
4. based on Ip+port the configuration of the virtual host
Edit configuration file/etc/httpd/conf/httpd.conf:listen 8080 #添加这一项 ..... ....... <VirtualHost192.168.1.11:80> ServerName www.a.com DOCUMENTROOT/VHOSTS/A.COM/HTDOCS/</VIRTUALHOST&G T;<virtualhost 192.168.1.21:80> ServerName www.b.org Documentroot/vhosts/b.org/htdocs/</virtualhos t> <VirtualHost192.168.1.11:8080> ServerName www.c.net Documentroot/vhosts/c.net/htdocs/</virtu alhost> #httpd-t#service httpd restart
Here we are based on Ip+port Virtual Host is configured, Access 192.168.1.199:80,192.168.1.101:80 in the browser , 192.168.1.101:8080 Test, observe the results
HTTP implementation of virtual host configuration