Preparatory work
Build a DNS first, create 3 domain names
[email protected] ~]# Yum install bind*
Modify the named.conf master configuration file
Listen-on Port: (any;};
allow-query {any;};
Zone "ccav.cn" in {
Type master;
File "Ccav.cn.zone";
};
Zone "ccav1.cn" in {
Type master;
File "Ccav1.cn.zone";
};
Zone "ccav2.cn" in {
Type master;
File "Ccav2.cn.zone";
};
Modify zone File contents
Ccav.cn.zone File Contents
$TTL 1D
@ in SOA server.ccav.cn. root.ccav.cn. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
@ NS server.ccav.cn.
server.ccav.cn. A 172.19.34.185
www.ccav.cn. A 172.19.34.185
Ccav1.cn.zone File Contents
$TTL 1D
@ in SOA server.ccav1.cn. root.ccav1.cn. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
NS server.ccav1.cn.
server.ccav1.cn. A 172.19.34.185
www.ccav1.cn. A 172.19.34.185
Ccav2.cn.zone File Contents
$TTL 1D
@ in SOA server.ccav2.cn. root.ccav2.cn. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
NS server.ccav2.cn.
server.ccav2.cn. A 172.19.34.185
www.ccav2.cn. A 172.19.34.185
Change which group the zone file belongs to
[Email protected] named]# chown named:named ccav.cn.zone ccav1.cn.zone ccav2.cn.zone
Shutting down the firewall
Service Iptables Stop
Turn off SELinux
Getenforce 0
Restart named service
[Email protected] named]# service named restart
Stopping named:. [OK]
Starting named: [OK]
To set the native IP to DNS
[Email protected] named]# cat/etc/resolv.conf
NameServer 172.19.34.185
Resolving domain Names
[Email protected] named]# host www.ccav.cn
Www.ccav.cn has address 172.19.34.185
[Email protected] named]# host www.ccav1.cn
Www.ccav1.cn has address 172.19.34.185
[Email protected] named]# host www.ccav2.cn
Www.ccav2.cn has address 172.19.34.185
DNS Domain name construction completed
-------------------------------------------------------------------------------------------
HTTP Service Installation
[[email protected] named] #yum install httpd*-y
-------------------------------------------------------------------------------------------
Host name-based virtual host
Modify the httpd.conf master configuration file
[Email protected] named]# vi/etc/httpd/conf/httpd.conf
Namevirtualhost *:80 Remove the front #
<virtualhost *:80>
Documentroot/var/http/www specifying page paths
ServerName www.ccav.cn Server Name
</VirtualHost>
<virtualhost *:80>
Documentroot/ccav1
ServerName www.ccav1.cn
</VirtualHost>
<virtualhost *:80>
Documentroot/ccav2
ServerName www.ccav2.cn
</VirtualHost>
New CCAV1,CCAV2, default/var/http/www is present, so do not add
[[email protected] named] #mkdir/ccav1/ccav2
Add a little content to the index.html.
[Email protected] named]# echo "This is www.ccav.cn ' s home" >/var/www/html/index.html
[Email protected] named]# echo "This is www.ccav1.cn ' s home" >/ccav1/index.html
[Email protected] named]# echo "This is www.ccav2.cn ' s home" >/ccav2/index.html
Change context
[[email protected] named] #chcon-R--reference=/var/www/html/ccav1/ccav2
Test
Open your browser and enter www.ccav.cn;www.ccav1.cn;www.ccav.cn to see if you can see what you just typed
-------------------------------------------------------------------------------------------
IP address-based virtual host
First create 2 I virtual IP addresses on the machine
[[Email protected] named]# IP addr Add 172.19.34.186/24 dev eth0 label eth0:1
[[Email protected] named]# IP addr Add 172.19.34.187/24 dev eth0 label Eth0:2
modifying network card files
[[email protected] named] #cp ifcfg-eth0 ifcfg-eth0:1
Device=eth0:1 Modify Name
hwaddr=00:0c:29:08:3a:56
Type=ethernet
Uuid=5d789fd9-45a5-4e87-b152-6cbd1a6f4d64
Onboot=yes
Nm_controlled=yes
Bootproto=static
ipaddr=172.19.34.186 Modifying IP addresses
netmask=255.255.255.0
gateway=172.19.34.254
dns1=172.19.34.185
CP Ifcfg-eth0 Ifcfg-eth0:2
Device=eth0:2 Modify Name
hwaddr=00:0c:29:08:3a:56
Type=ethernet
Uuid=5d789fd9-45a5-4e87-b152-6cbd1a6f4d64
Onboot=yes
Nm_controlled=yes
Bootproto=static
ipaddr=172.19.34.187 Modifying IP addresses
netmask=255.255.255.0
gateway=172.19.34.254
dns1=172.19.34.185
Finish modifying and restarting
[[email protected] named] #service network restart
Modify DNS zone file a record
Ccav1.cn.zone
$TTL 1D
@ in SOA server.ccav1.cn. root.ccav1.cn. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
NS server.ccav1.cn.
server.ccav1.cn. A 172.19.34.186
www.ccav1.cn. A 172.19.34.186
Ccav2.cn.zone
$TTL 1D
@ in SOA server.ccav2.cn. root.ccav2.cn. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
NS server.ccav2.cn.
server.ccav2.cn. A 172.19.34.187
www.ccav2.cn. A 172.19.34.187
Modify the httpd primary configuration file
Vi/etc/httpd/conf/httpd.conf
#NameVirtualHost *:80#必须注释掉
Change * to the appropriate IP address
<virtualhost 172.19.34.185:80>
Documentroot/var/www/html
ServerName www.ccav.cn
</VirtualHost>
<virtualhost 172.19.34.186:80>
Documentroot/ccav1
ServerName www.ccav1.cn
</VirtualHost>
<virtualhost 172.19.34.187:80>
Documentroot/ccav2
ServerName www.ccav2.cn
</VirtualHost>
Restart httpd
[[email protected] named] #service httpd restart
Test effect
Open IP in IE, or Web page can be accessed
This article is from the "zhufaqing" blog, make sure to keep this source http://19851225.blog.51cto.com/1088033/1583217
WWW Server virtual Host configuration