(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 <IP地址或网段列表>
使用not禁止访问时要将其置于<RequireAll></RequireAll>容器中并在容器中指定相应的限制策略
Require的命令模式
安装DNS 和httpd 服务
[root@localhost ~]# yum install bind httpd -y
修改DNS 主配置文件
[root@localhost ~]# vim /etc/named.conf
配置DNS区域配置文件
[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
在windows10 上打开cmd测试是否能解析到域名
[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 //创建扩展文件
<VirtualHost *:80> //标题,固定格式
DocumentRoot "/var/www/html/kgc" //站点
ServerName www.kgc.com //域名
ErrorLog "logs/www.kgc.com.error_log" //错误日志文件
CustomLog "logs/www.kgc.com.access_log" common //访问日志文件
<Directory "/var/www/html/">
Require all granted //访问权限
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/accp"
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
配置网页显示内容
[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
<h2>this is kgc web</h2>
[root@localhost kgc]# cd ../accp/
[root@localhost accp]# vim index.html
<h2>this is accp web</h2>
配置网页的绝对路径
[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
<VirtualHost *:8080>
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 <Directory "/var/www/html/">
27 Require all granted
28 </Directory>
29 </VirtualHost>
[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
<h2>this is accp02 web</h2>
进入绝对路径,修改
[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 <VirtualHost 192.168.45.135:80>
2 DocumentRoot "/var/www/html/kgc"
3 ErrorLog "logs/www.kgc.com.error_log"
4 CustomLog "logs/www.kgc.com.access_log" common
5 <Directory "/var/www/html/">
6 Require all granted
7 </Directory>
8 </VirtualHost>
9
10 <VirtualHost 192.168.45.128:80>
11 DocumentRoot "/var/www/html/kgc02"
12 ErrorLog "logs/www.kgc02.com.error_log"
13 CustomLog "logs/www.kgc02.com.access_log" common
14 <Directory "/var/www/html/">
15 Require all granted
16 </Directory>
17 </VirtualHost>
创建网页文件,并添加网页显示内容
[root@localhost extra]# cd /var/www/html/
[root@localhost html]# mkdir kgc02
[root@localhost html]# cd kgc02/
[root@localhost kgc02]# vim index.html
<h2>this is kgc02 web</h2>
进入http配置文件
[root@localhost kgc02]# vim /etc/httpd/conf/httpd.conf
重启网页服务
[root@localhost kgc02]# systemctl restart httpd
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。