httpd网站服务

 

实验一

基本HTTP服务器的配置

主机名设为:www.tarena.com192.168.10.10

默认首页包括:index.html、index.php

开启保持连接

确认默认httpd是否支持php

前提条件在客户端配置hosts文件

192.168.10.10www.tarena.comwww

 

1、软件包的安装

[root@localhost ~]# yum -y install httpd

2、修改主配置文件

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 

...

74 KeepAlive On(始终连接)

...

265 ServerName www.tarena.com:80(设置网站名称)

...

391 DirectoryIndex index.html index.php(设置默认索引页/首页文件)

...

3、启动服务

[root@localhost ~]# service httpd restart

[root@localhost ~]# chkconfig httpd on

新建测试页面

[root@localhost ~]# cat /var/www/html/index.html (新建并编辑)

<html>

<head><title>This is a test Page!!!</title>

<body>

<h1>This is www.tarena.com test Page!!!</h1>

</body>

</head>

</html>

[root@localhost ~]# cat /var/www/html/index.php 

<?php

phpinfo();

?>

 

测试

http://www.tarena.com

http://www.tarena.com/index.php (测试是否运行php,如果访问网页显示如上内容表示在运行)

总结:

安装后,默认访问会出现403报错,但这里显示的是Linux欢迎界面,同样表示报错。不要误解噢!!

 

 

实验二:HTTP的访问控制

只允许192.168.10.5访问www.tarena.com

允许所有用户访问www.tarena.com/authdir/index.html

1、修改主配置文件

[root@localhost ~]# mkdir /var/www/html/authdir

[root@localhost ~]# cat /var/www/html/authdir/index.html 

<html>

<head><title>This is a test Page!!!</title>

<body>

<h1>This is http://www.tarena.com/authdir/index.html!!!</h1>

</body>

</head>

</html>

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

...

306 <Directory "/var/www/html">

...

332Order allow,deny

333 #Allow from all(拒绝所有 加#号 表示不启用)

334Allow from 192.168.10.5

...

337 <Directory "/var/www/html/authdir">

338Order allow,deny

339Allow from all

340 </Directory>

2、启动服务

[root@localhost ~]# service httpd restart

3、在不同客户端测试

[root@localhost ~]# tail /var/log/httpd/error_log (查看日志,用来分析登录信息,error表示不正常的)

...

[Wed Apr 16 16:52:31 2014] [error] [client 192.168.10.6] client deniedby server configuration: /var/www/html/

试验三:HTTP的用户授权

客户端访问/var/www/html/authdir/需要输入用户名密码验证

 

1、修改主配置文件

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 

...

337 <Directory "/var/www/html/authdir">

338Order allow,deny

339Allow from all

340AuthName "Please Input Password!!"(认证领域名称,用于弹窗提示)

341AuthType Basic(认证类型,一般使用basic(基本))

342AuthUserFile "/etc/httpd/.vuser"(用户数据文件的路径)

343Require valid-user(指定授权用户或组)

344 </Directory>

...

2、创建账户密码

[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

http://www.tarena.com/authdir

 

实验四:HTTP目录别名

客户端访问http://www.tarena.com/sina时可以访/var/www/html/sina.com/bbs下的网页

1、创建测试站点

[root@localhost ~]# mkdir -p /var/www/html/sina.com/bbs

[root@localhost ~]# cat /var/www/html/sina.com/bbs/index.html 

<html>

<head><title>This is a test Page!!!</title>

<body>

<h1>This is bbs.sina.com test Page!!!</h1>

</body>

</head>

</html>

2、修改主配置文件

[root@localhost ~]# tail -n 1 /etc/httpd/conf/httpd.conf (查看最后一行,需要编写)

Alias /sina"/var/www/html/sina.com/bbs"

3、启动服务测试

[root@ser1 ~]# service httpd restart

http://www.tarena.com/sina