您的位置:首页 > 理论基础 > 计算机网络

Linux网络服务之HTTP(1)

2014-05-03 10:24 459 查看
Linux网络服务之HTTP(1)
实验要求:
1、主机名设为:www.zhy.com,默认首页包括:index.html、index.php,开启保持连接,确认默认httpd是否支持php
2、只允许192.168.1.1访问www.zhy.com,允许所有用户访问www.zhy.com/user/index.html
3、客户端访问/var/www/html/admin/需要输入用户名密码验证
4、客户端访问http://www.zhy.com/bbs时可以访问/var/www/html/user/bbs下的网页
实验步骤:
1、安装软件包
搭建http服务需要安装软件包httpd
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# vim /var/www/html/index.html //准备访问界面
前提需配置DNS为网站做域名解析
2、修改配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //修改http服务主配置文件
……
74 KeepAlive On //开启保持连接功能
……
265 ServerName www.zhy.com //设置域名
……
281 DocumentRoot "/var/www/html" //网站默认根目录
……
306 <Directory "/var/www/html">
……
332 Order allow,deny
333 # Allow from all //默认允许所有人访问,此处注释掉
334 Allow from 192.168.1.1 //只允许该IP地址访问
……
</Directory>
336 <Directory "/var/www/html/user"> //设置对该目录的访问控制
337 Order allow,deny
338 Allow from all //允许所有人访问
339 </Directory>
340 <Directory "/var/www/html/admin">
341 Order allow,deny //先允许,后拒绝,默认拒绝所有
342 Allow from all
343 AuthName "Please Input Password" //弹窗提示
344 AuthType Basic //认证类型
345 AuthUserFile "/etc/httpd/.vuser" //认证文件
346 Require valid-user //指定授权用户或组
347 </Directory>
348 Alias /bbs/ "/var/www/html/bbs" //设置别名
……
391 DirectoryIndex index.html index.php //默认主页文件
……
[root@localhost ~]# htpasswd -c /etc/httpd/.vuser admin //创建认证用户
New password: //创建密码
Re-type new password:
Adding password for user admin
3、启动服务,设置服务开机自动启动
[root@localhost ~]# service httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
[root@localhost ~]# chkconfig httpd on
4、测试
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息