实验需求
配置基于域名的虚拟主机,必须用以下域名访问
要求这两个虚拟站点分别存放日志文件
只有访问时,要求输入账户news密码123后能看到/usr/html目录下test.htm网页内容
只有88181.com有news别名,linuxidc.com没有news别名
配置只允许网段中一台主机能访问
配置仅不允许能访问linuxidc的那台主机访问
服务器端
1.安装所需的软件包
[root@rhel5 ~]# yum install httpd -y2.添加虚拟主机的配置文件
[root@rhel5 ~]# cd /etc/httpd/conf.d/
[root@rhel5 conf.d]# vim vhost.conf
[root@rhel5 conf.d]# vim vhost.conf
[root@rhel5 conf.d]# cat vhost.confNameVirtualHost 10.0.1.8:80 #指定主机ip和监听端口
<VirtualHost 10.0.1.8:80>
DocumentRoot /var/www/html/yum #虚拟主机的文件家目录
ServerName #虚拟主机的域名
ErrorLog logs/yum.com-error_log #虚拟主机的日志文件
CustomLog logs/yum.com-access_log common
</VirtualHost>
<VirtualHost 10.0.1.8:80>
DocumentRoot /var/www/html/88181
ServerName
alias /news /usr/html #设置别名
<Directory /usr/html> #用户认证
AuthName "please input password "
AuthType Basic
AuthUserFile /etc/httpd/.htpasswd
require user news
</Directory>
<Directory /var/www/html/88181>
Order deny,allow #访问控制
Deny from 10.0.1.238
</Directory>
ErrorLog logs/88181.com-error_log
CustomLog logs/88181.com-access_log common
</VirtualHost>
<VirtualHost 10.0.1.8:80>
DocumentRoot /var/www/html/linuxidc
ServerName
<Directory /var/www/html/linuxidc>
Order allow,deny
Allow from 10.0.1.238
</Directory>
ErrorLog logs/linuxidc.com-error_log
CustomLog logs/linuxidc.com-access_log common
</VirtualHost>
3.添加所需要的目录和文件夹
#创建各个虚拟主机的根目录
[root@rhel5 named]# cd /var/www/html/
[root@rhel5 html]# mkdir yum 88181 linuxidc
[root@rhel5 conf.d]# mkdir /usr/html#添加标志性文件
[root@rhel5 html]# echo "this is a yum" >yum/index.html
[root@rhel5 html]# echo "this is a 88181" >88181/index.html
[root@rhel5 html]# echo "this is a linuxidc" >linuxidc/index.html
[root@rhel5 conf.d]# echo "this is a 88181 news" >/usr/html/index.html#添加news目录用户认知
[root@rhel5 conf.d]# htpasswd -c -b /etc/httpd/.htpasswd news 123 Adding password for user /etc/httpd/.htpasswd#挂载光盘镜像到的家目录
[root@rhel5 conf.d]# mount /dev/cdrom /var/www/html/yum4.修改dns主配置文件(这里使用我上次配置好的dns服务器,新添加3个域就行了)
[root@rhel5 conf.d]# vim /var/named/chroot/etc/named.conf
[root@rhel5 conf.d]# tail -13 /var/named/chroot/etc/named.confzone "yum.com" IN{
type master;
file "yum.com.zone";
};
zone "88181.com" IN{
type master;
file "88181.com.zone";
};
zone "linuxidc.com" IN{
type master;
file "linuxidc.com.zone";
};
5.添加dns区域(zone)配置文件
[root@rhel5 conf.d]# cd /var/named/chroot/var/named/
[root@rhel5 named]# cp -a sw.com.zone yum.com.zone
[root@rhel5 named]# cp -a sw.com.zone 88181.com.zone
[root@rhel5 named]# cp -a sw.com.zone linuxidc.com.zone#yum.com配置文件
[root@rhel5 named]# vim yum.com.zone
[root@rhel5 named]# cat yum.com.zone
$TTL 86400
@ IN SOA root (
2013080803 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
@ IN NS
@ IN A 10.0.1.8
www IN A 10.0.1.8#88181.com配置文件
[root@rhel5 named]# vim 88181.com.zone
[root@rhel5 named]# cat 88181.com.zone
$TTL 86400
@ IN SOA root (
2013080803 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
@ IN NS
@ IN A 10.0.1.8
www IN A 10.0.1.8#linuxidc.com配置文件
[root@rhel5 named]# vim linuxidc.com.zone
[root@rhel5 named]# cat linuxidc.com.zone