RHCE_RHEL6_实战精品 3.web服务器_虚拟主机
企业需求:
一、配置web服务器,能被http://dtop30.dn.ws.com访问
二、配置web服务器,实现虚拟主机。 http://www30.dn.ws.com能访问到/www/virtual目录下的页面,
页面从http://ip/dir/restircted.html下载。
并保证,http://dktop30.dn.ws.com同样能被访问到之前的内容。
三、从http://ip/dir/restircted.html下载文件,能被本地用户sisi通过路径
http://dtop.dn.ws.com/restircted访问到,但是不可以被remote.com域访问。
实施步骤:
一、配置web服务器,能被http://dtop30.dn.ws.com访问
1.安装httpd,并启动服务。 [root@dtop30 ~]# rpm -qa |grep httpd
[root@dtop30 ~]# yum -y install httpd
[root@dtop30 ~]# chkconfig httpd on
[root@dtop30 ~]# service httpd start
2.首先要通读题意:这里最终要创建2个web站点,一个是http://dtop30.dn.ws.com,
还有一个是http://www30.dn.ws.com。所以,2个都必定是虚拟主机!
配置httpd的主配置文件。
[root@dtop30 ~]# vim /etc/httpd/conf/httpd.conf

3.编写web页面。
[root@dtop30 ~]# vim /var/www/html/index.html

4.重启httpd服务。测试:
[root@dtop30 ~]# service httpd restart
[root@dtop30 ~]# elinks http://dtop30.dn.ws.com

ok!
二、配置虚拟主机。 http://www30.dn.ws.com能访问到/www/virtual目录下的页面,
页面从http://ip/dir/restircted.html下载。
并保证,http://dtop30.dn.ws.com同样能被访问到之前的内容。
1.配置httpd主配置文件,添加虚拟主机www30.dn.ws.com。
[root@dtop30 ~]# vim /etc/httpd/conf/httpd.conf

2.创建网页目录,并赋予http类型的context值。
[root@dtop30 ~]# mkdir -p /www/virtual
[root@dtop30 ~]# ls -lZ /var/www/html

[root@dtop30 ~]# semanage fcontext -a -t httpd_sys_content_t ‘/www(/.*)?’
[root@dtop30 ~]# restorecon –vFR /www
3.下载指定内容的页面
[root@dtop30 ~]# cd /www/virtual
[root@dtop30 virtual]#
4.下载网页:http://ip/dir/

右键 restircted.html

Name:index.html
保存位置选择:Browse for other folders --->/www/virtual --->save

5.查看内容,查看context。
[root@dtop30 virtual]# cat index.html
[root@dtop30 virtual]# ls -lZ index.html
6.重启httpd服务。测试 :
[root@dtop30 virtual]# service httpd restart
[root@dtop30 virtual]# elinks http://www30.dn.ws.com

ok!
[root@dtop30 virtual]# elinks http://dtop30.dn.ws.com

ok!