注意:网站服务器匹配原则。分两部分,局部生效和全局生效。局部生效的优先级大于全局生效。当用户自己创建了局部网站时,会优先匹配到局部搭建的网站信息。通俗来说,默认的全局下的网站页面信息是用来兜底的。
要求:
1.要求搭建web服务器,能够访问到网页内容为“小胖,你咋这么胖呢!”
2.要求搭建web服务器,创建基于域名的虚拟主机,能够使用www.xiaopang.com和www.dapang.com访问各自的网站网站存放路径分别为/xiaopang和/dapang,内容自定
- 安装软件包
- 开启httpd服务
- 关闭防火墙
- 关闭selinux
- 通过IP访问apache默认网站页面。
/var/www/html是默认的网站加载页面,是全局生效的。这时我们通过自己在该目录下创建一个index.html文件后,输入内容后就会,再次通过IP访问网站时就会匹配到自己创建的网站页面而不是默认apache网站页面。
- 创建虚拟主机,实现通过域名访问
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
<VirtualHost 192.168.100.128:80> //创建虚拟主机IP为192.168.100.128,监听端口80
ServerName xiaopang //服务器的名字
ServerAlias www.xiaopang.com //别名,也就是可以使用域名来进行一个访问
ErrorLog "/var/log/httpd/dummy-host.example.com-error_log" //错误日志信息
CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost 192.168.100.129:80>
DocumentRoot "/dapang
ServerName dapang
ServerAlias www.dapang.com
ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>
<Directory /xiaopang> //根目录
AllowOverride none //不允许覆写
Require all granted //允许访问
</Directory>
<Directory /dapang>
AllowOverride none
Require all granted
</Directory>
- 完成vim编辑后,重启服务。由于没有创建xiaopang和dapang目录,所以需要先创建目录,然后再各自的目录中写入内容,并以index.html文件格式结尾。
注:由于是要通过域名访问,所以我们要再本地缓存中去添加相对应的域名。
Redhat的本地缓存文件在该目录下
vim /etc/hosts
进行IP和域名的添加
Redhat测试
- windows测试也需要在本地缓存中添加相应的域名
c/windows/system32/drivers/hosts
通过域名进行访问小胖网站
通过域名访问大胖网站