一. 实验准备
- 1. 准备三台虚拟机,ip在同一个网段之间能互通。
- 2. 服务器机安装了HTTP软件包。
二. 实验一准备环境:
- 1. 设置ip (其它两台机器改成同一个网段的配置方法如下:)
[iyunv@localhost~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 //查看配置的ip如需修改把“cat” 改为“vim”
# IntelCorporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none //这个默认类型就能使用
HWADDR=00:0C:29:6F:36:09 //本机MAC地址
ONBOOT=yes
NETMASK=255.255.255.0 //子网掩码
IPADDR=192.168.4.5 //本机ip地址
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
[iyunv@localhost~]# cat /etc/hosts //查看配置文件
# Do not removethe following line, or various programs
# that requirenetwork functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.4.5 www.tarena.com tarena.com //服务器ip 、域名、主机头域名解析,就是把域名解析为该ip
3.检测是否安装http软件包
[iyunv@localhost~]# rpm -q httpd //检测方法后面跟要检测的包名
httpd-2.2.3-74.el5 //代表已安装
三.试验二:基本HTTP服务器的配置
Web服务器域名:www.tarena.com
默认首页包括:index.html、index.php
开启保持连接
确认默认httpd是否支持php
网站用老师提供的test_web.zip测试
[iyunv@localhost~]# cd /etc/httpd/conf/ //切换到该目录下
[iyunv@localhostconf]# cp httpd.conf httpd.conf.txt //备份该主配置文件以防修改出错时使用
[iyunv@localhostconf]# vim /etc/httpd/conf/httpd.conf //修改主配置文件
74 KeepAlive On //是否保持连接默认off
265 ServerName www.tarena.com:80 //服务目录(域名)后面是端口号
391 DirectoryIndexindex.html index.php //默认首页显示的文件
[iyunv@localhostconf]# service httpd restart //重启http服务,这样修改才会生效。
[iyunv@localhost~]# cd Desktop/ //切换到该目录
[iyunv@localhostDesktop]# unzip test_web.zip //解压该软件包到该目录
[iyunv@localhostDesktop]# ls //查看该目录文件
httpd-2.2.25.tar.gz jiajutiyan sirbiz test_web.zip
[iyunv@localhostDesktop]# mv jiajutiyan/* /var/www/html/ //把解压的文件复制到http网站根目录中
[iyunv@localhost~]# vim /var/www/html/test.php //编辑该文件
[iyunv@localhost~]# cat /var/www/html/test.php //查看编辑的内容
<?php
phpinfo();
?>
先在客户机上hosts文件指定nds的解析
192.168.4.5 www.tarena.com tarena.com
打开浏览器分别输入以下网站
http://www.tarena.com
http://www.tarena.com/test.php
总结:
通过实验发现http支持php服务。
四.实验三http的访问控制
[iyunv@localhost~]# mkdir /var/www/html/authdir //创建文件
[iyunv@localhost~]# mv /root/Desktop/sirbiz/* /var/www/html/authdir/ //把刚才解压的另一个网站放到该目录下
- 2. 让指定ip访问该网页(192.168.4.10)
[iyunv@localhostconf]# vim /etc/httpd/conf/httpd.conf //修改配置文件
336 <Directory"/var/www/html/authdir"> //添加一行这个开头后面是路径
337 Order allow,deny
338 Allow from 192.168.4.10 //指定的ip地址
339</Directory> //结尾
[iyunv@localhostconf]# service httpd restart //重启
在2台客户端进行测试输入以下网站
www.tarena.com/authdir
五.试验四:HTTP的用户授权
客户端访问http://www.tarena.com/authdir需要输入用户名密码验证
- 1. 修改主配置文件(访问authdir时才用验证所以添加到该配置里
[iyunv@localhost~]# vim /etc/httpd/conf/httpd.conf //编辑配置文件
340 AuthName "qing shu ru mi ma" //窗口提示
341 AuthType basic //类型一般是basic
342 AuthUserFile "/etc/httpd/.http" //用户数据路径
343 Require valid-user //指定授权组这是全部
[iyunv@localhostconf]# service httpd restart //重启
[iyunv@localhost~]# htpasswd -c /etc/httpd/.http jx //创建账户,最后跟的是账户。中间路径是主配置文件里的路径
Newpassword: //密码
Re-typenew password: //确认密码
Addingpassword for user jx //成功创建
输入网站www.tarena.com/authdir进行测试,如果成功则需输入密码失败就不用。
六.实验五:HTTP目录别名
客户端访问http://www.tarena.com/sina时可
以访问/var/www/html/sina.com/bbs下的网页
[iyunv@localhost~]# mkdir -p /var/www/html/sina.com/bbs //创建文件加-p递归 [iyunv@localhost~]# echo "www.baidu.com" > /var/www/html/sina.com/bbs //重定向内容 Alias/sina "/var/www/html/sina.com/bbs" //添加目录别名 七.实验六:
查看默认HTTP使用进程管理方式更改默认进程管理方式为worker模式
1.查看进程
[iyunv@localhost~]# httpd -l //查看进程方式
Compiledin modules:
core.c
prefork.c //现在的进程模式
http_core.c
mod_so.c
2.修改进程方式
[iyunv@localhost~]# cd /usr/sbin/ //切换到进程目录
[iyunv@localhostsbin]# mv httpd httpd.prefork //修改名字
[iyunv@localhostsbin]# mv httpd.worker httpd //修改名字
[iyunv@localhostsbin]# service httpd restart //重启
3.查看结果
[iyunv@localhostsbin]# httpd –l //再次查看进程发现变了
Compiledin modules:
core.c
worker.c //先在的进程模式
http_core.c
mod_so.c
|