(1)基于域名
(2)基于端口
(3)基于IP
在同一台物理服务器中运行多个web站点,其中每一个站点并不独立占用一台真正的计算机
(1)基于域名的虚拟主机
(2)基于IP地址的虚拟主机
(3)基于端口的虚拟主
(1)KeepAlive
是否打开连接保持,OFF关闭,ON 打开
(2)KeepAlive Timeout
一次连接多粗请求之间的最大间隔时间,两次请求超过该时间连接断开
(3)MaxKeepAliveRequests
一次连接能够传输的最大请求数量
(1)作用
控制对网站资源的访问
为特定的网站目录添加访问权限
(2)常用的访问控制方式
客户机地址限制
用户限制
Require all granted
Require all denied
Require local
Require [not ] host <主机名或域名列表>
Require [not ] ip
使用not禁止访问时要将其置于容器中并在容器中指定相应的限制策略
Require的命令模式
安装DNS 和httpd 服务
[root@localhost ~]# yum install bind httpd -y
修改DNS 主配置文件
[root@localhost ~]# vim /etc/named.conf
[root@localhost ~]# vim /etc/named.rfc1912.zones
#在区域配置文件中添加下列内容
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
zone "accp.com" IN {
type master;
file "accp.com.zone";
allow-update { none; };
};
配置DNS 区域数据配置文件
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls //查看
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p named.localhost kgc.com.zone
[root@localhost named]# vim kgc.com.zon
将kgc的区域数据配置文件,复制一份复制到accp下不做修改
[root@localhost named]# cp -p kgc.com.zone accp.com.zone
开启DNS服务、关闭防火墙和安全功能
[root@localhost named]# systemctl start named
[root@localhost named]# systemctl stop firewalld.service
[root@localhost named]# setenforce 0
[root@localhost named]# cd /etc/httpd/
[root@localhost httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@localhost httpd]# cd conf/
[root@localhost conf]# ls
httpd.conf magic
[root@localhost conf]# mkdir extra
[root@localhost conf]# cd extra/
[root@localhost extra]# vim vhost.conf //创建扩展文件
//标题,固定格式
DocumentRoot "/var/www/html/kgc" //站点
ServerName www.kgc.com //域名
ErrorLog "logs/www.kgc.com.error_log" //错误日志文件
CustomLog "logs/www.kgc.com.access_log" common //访问日志文件
Require all granted //访问权限
DocumentRoot "/var/www/html/accp"
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
Require all granted
配置网页显示内容
[root@localhost httpd]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# mkdir kgc accp
[root@localhost html]# ls
accp kgc
[root@localhost html]# cd kgc/
[root@localhost kgc]# vim index.html
this is kgc web
[root@localhost kgc]# cd ../accp/
[root@localhost accp]# vim index.html
this is accp web
配置网页的绝对路径
[root@localhost accp]# cd /etc/httpd/
[root@localhost httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@localhost httpd]# cd conf/
[root@localhost conf]# vim httpd.conf
Include conf/extra/vhost.conf
启动http服务
[root@localhost conf]# systemctl start httpd
进入扩展文件,配置,添加一个端口
[root@localhost conf]# cd extra/
[root@localhost extra]# vim vhost.conf
22 DocumentRoot "/var/www/html/accp02"
23 ServerName www.accp.com
24 ErrorLog "logs/www.accp02.com.error_log"
25 CustomLog "logs/www.accp02.com.access_log" common
26
27 Require all granted
28
29
[root@localhost extra]# cd /var/www/html/ //创建accp02 zhandian
[root@localhost html]# ls
accp kgc
[root@localhost html]# mkdir accp02
[root@localhost html]# cd accp02/
[root@localhost accp02]# vim index.html
this is accp02 web
进入绝对路径,修改
[root@localhost accp02]# vim /etc/httpd/conf/httpd.conf
[root@localhost accp02]# systemctl restart httpd
查看端口
[root@localhost accp02]# netstat -ntap
基于IP要不同的IP地址,我们首先在虚拟机上添加一个网卡,然后让他自动获取IP地址。
第二块网卡添加成功,他的IP地址为192.168.45.128
进入vhost.conf修改,设置基IP 的配置
[root@localhost accp02]# cd /etc/httpd/conf/extra/
[root@localhost extra]# vim vhost.conf
1
2 DocumentRoot "/var/www/html/kgc"
3 ErrorLog "logs/www.kgc.com.error_log"
4 CustomLog "logs/www.kgc.com.access_log" common
5
6 Require all granted
7
8
9
10
11 DocumentRoot "/var/www/html/kgc02"
12 ErrorLog "logs/www.kgc02.com.error_log"
13 CustomLog "logs/www.kgc02.com.access_log" common
14
15 Require all granted
16
17
创建网页文件,并添加网页显示内容
[root@localhost extra]# cd /var/www/html/
[root@localhost html]# mkdir kgc02
[root@localhost html]# cd kgc02/
[root@localhost kgc02]# vim index.html
this is kgc02 web
进入http配置文件
[root@localhost kgc02]# vim /etc/httpd/conf/httpd.conf
[root@localhost kgc02]# systemctl restart httpd