httpd配置实验

系统:RHEL6.4

客户端防火墙关闭

服务端防火墙关闭                                    

注:未配置DNS,暂使用host文件来测试

Windows:

修改C:\Windows\System32\drivers\etc下hosts文件

192.168.10.253      www.httpdtest.com 

                               实验一


设置条件:

主机名设为:www.httpdtest.com 192.168.10.253

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

开启保持连接

确认默认httpd是否支持php


1.软件包发安装

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

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0                                                                                

TYPE=Ethernet                                                                     

ONBOOT=yes                                                         

BOOTPROTO=static                                              

IPADDR=192.168.10.253

NETMASK=255.255.255.0

2.修改主配置文件

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

...

74  KeepAlive On                               //开启保持连接

.....

277 ServerName www.httpdtest.com:80            //本站点的FQDN名称 

....

401 DirectoryIndex index.html index.php       //默认首页/索引页文件

.....

3.启动服务

[root@localhost ~]#service httpd restart

[root@localhost ~]#chkconfig httpd on

4.新建测试页面

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

<html>

<head>

<title>TEST PAGE</title>

</head>

<body>

<h1>This is www.httpdtest.com Test Page!!!</h1>

</body>

</html>

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

<?php

        phpinfo();

?>

5.客户端测试

http://www.tarena.com

http://www.tarena.com/index.php




                                      实验二

要求:

      只允许192.168.10.21访问www.httpftest.com

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

1.安装软件包

2.修改配置文件

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

......

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

....

332 Order allow,deny                              //先允许后拒绝

333 Allow from 192.168.10.21                      //只允许192.168.10.21

...

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

         Order allow,deny

         Allow from all                          //允许所有

340  </Directory>

3.    启动服务

[root@localhost ~]#service httpd restart

4.在不同客户端测试http://www.tarena.com

[root@localhost ~]#tail /var/log/httpd/error_log       //查看日志验证实验是否成功



                         实验三:HTTP的用户授权


     客户端访问www.httpdtest.com/authdir/需要输入用户名密码验证

1.修改主配置文件

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

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

         Order allow,deny

         Allow from all

         AuthName "Please Inout Password"           //认证名称,用于弹窗显示

         AuthType Basic                             //认证类型,一般使用basic

         AuthUserFile "/etc/httpd/.vuser"           //用户数据文件路径

         Require valid-user                         //指定授权用户名或组

344  </Directory>

2.创建帐户密码

[root@localhost ~]# htpasswd -c /etc/httpd/.auth.list admin

New passwd:

Re-type new password:

Adding passwd for user admin

3.启动服务测试

[root@localhost ~]# service httpd restart

http://www.tarena.com/authdir




                          实验四:HTTP目录别名

      客户端访问www.httpdtest.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

2.修改主配置文件

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

548 Alias /sina "/var/www/html/sina.com/bbs"                    //添加别名

3.启动服务测试

[root@localhost ~]#service httpd restart

http://www.httpdtest.com/sina




                      实验五: 部署Awstats统计HTTP访问日志

1.安装软件

[root@localhost ~]#cd /usr/src

[root@localhost src]#tar -zxvf awstats-7.1.tar.gz -C /usr/local/

[root@localhost src]#cd /usr/local

[root@localhost local]#mv awstats-7.1/ awstats

2.为站点建立配置文件

[root@localhost ~]#cd /usr/local/awstats/tool/

[root@localhost ~]#./awstats_configure.pl

...

Config file path ('none' to skip web server setup):

> /etc/httpd/conf/httpd.conf                      //输入apache的主配置文件

?y                                                //同意创建新的站点配置      

>www.httpftest.com                                //指定网站名称

>                                                 //回车,接受配置路径/etc/awstats

                                                  //   ......自动重启httpd服务

>                                                 // 回车,继续

>                                                 //回车,完成配置

3.修改主配置文件

[root@localhost tools]# vim /etc/awstats/awstats.www.httpdtest.com.conf

...

51  LogFiel="/var/log/httpd/access_log"

[root@localhost tools]# mkdir /var/lib/awstats

4.将日志文件导入Awstats

[root@localhost ~]#./awstats_updateall.pl now

[root@localhost ~]#crontab -e                              //添加计划任务每五分钟导入一次

*/5  *  *   * * /usr/local/awstats/tools/awstats_updateall.pl now    

[root@localhost ~]#service crond restart

[root@localhost ~]#chkconfig crond on

5.验证:

客户端浏览器输入

http://www.httpdtest.com/awstats/awstats.pl?config=www.httpdtest.com //查看图表 

补充:通过html代码实现网页跳转功能

访问awstats.html时相当于访问http://www.httpdtest.com/awstats/awstats.pl?config=www.httpdtest.com

[root@localhost ~]#vim /var/www/html/awstats.html

<html>

<head>

<meta http-equiv=refresh content="0;url=http://www.httpdtest.com/awstats/awstats.pl?config=www.httpdtest.com">

</head>

<body>

</body>

</html>




实验六:基于域名的虚拟主机

               当用户访问www.baidu.com的时候访问baidu网站

               当用户访问www.google.com的时候访问google网站

               baidu,google的IP地址一样

               确保上面www.httpdtest.com还能访问

前提条件配置hosts

192.168.10.253              www.httpdtest.com       www

192.168.10.253              www.baidu.com       www

192.168.10.253              www.google.com       www

1.创建网站存放路径

[root@localhost ~]#mkdir -p /data/web/{www,google}

[root@localhost ~]#vim /data/web/baidu/index.html

<html>

<head>

<title>百度测试页</title>

</head>

<body>

<h1>This is www.baidu.com Test Page!!!</h1>

</body>

</html>

[root@localhost ~]#vim /data/web/google/index.html

<html>

<head>

<title>谷歌测试页</title>

</head>

<body>

<h1>This is www.google.com Test Page!!!</h1>

</body>

</html>

2.修改主配置文件

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

NameVirtualHost *:80

<VirtualHost *:80>

DocumentRoot /var/www/html

ServerName www.httpdtest.com

ErrorLog logs/httpdtest.com-error_log

CustomLog logs/httpdtest.com-access_log common

</VirtualHost> 

<VirtualHost *:80>

DocumentRoot /data/web/baidu

ServerName www.baidu.com

ErrorLog logs/baidu.com-error_log

CustomLog logs/baidu.com-access_log common

</VirtualHost>

<VirtualHost *:80>

DocumentRoot /data/web/google

ServerName www.google.com

ErrorLog logs/google.com-error_log

CustomLog logs/google.com-access_log common

</VirtualHost>  

3.启动服务

[root@localhost ~]# service httpd restart

4.客户端测试

http://www.httpdtest.com

http://www.baidu.com

http://www.google.com



实验七:基于IP的虚拟主机

前提条件配置hosts

192.168.10.10              www.httpdtest.com       www

192.168.10.11              www.baidu.com       www

192.168.10.12              www.google.com       www

1.建立网站存放路径...略

2.设置IP

[root@localhost ~]#cd /etc/sysconfig/network-scripts/

[root@localhost ~]#cp ifcfg-eth0 ifcfg-eth0:0

[root@localhost ~]#cp ifcfg-eth0 ifcfg-eth0:1

[root@localhost ~]#vim /ifcfg-eth0:0

DEVICE=eth0:0

BOOTPROTO=none

ONBOOT=yes

IPADDR=192.168.10.11

NETMASK=255.255.255.0

[root@localhost ~]#vim /ifcfg-eth0:1

DEVICE=eth0:1

BOOTPROTO=none

ONBOOT=yes

IPADDR=192.168.10.12

NETMASK=255.255.255.0

[root@localhost ~]#service network restart 

3.修改主配置文件

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

<VirtualHost 192.168.10.10>

DocumentRoot /var/www/html

ServerName www.httpdtest.com

ErrorLog logs/httpdtest.com-error_log

CustomLog logs/httpdtest.com-access_log common

</VirtualHost> 

<VirtualHost 192.168.10.11>

DocumentRoot /data/web/baidu

ServerName www.baidu.com

ErrorLog logs/baidu.com-error_log

CustomLog logs/baidu.com-access_log common

</VirtualHost>

<VirtualHost 192.168.10.12>

DocumentRoot /data/web/google

ServerName www.google.com

ErrorLog logs/google.com-error_log

CustomLog logs/google.com-access_log common

</VirtualHost>

4.启动服务

[root@localhost ~]#service httpd restart

5.测试

http://www.httpdtest.com

http://www.baidu.com

http://www.google.com

ping www.httpdtest.com

ping www.baidu.com

ping www.google.com



实验八:基于端口的虚拟主机

           www.httpdtest.com:80                    tarena.com 的网站

           www.baidu.com:8080                      baidu.com 的网站

           www.google.com:8081                     google.com 的网站

  1. 建立网站存放路径...略

  2. 修改主配置文件

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

Listen 80

Listen 8080

Listen 8081

#NameVirtualHost *:80                        //不需要

<VirtualHost 192.168.10.10:80>

DocumentRoot /var/www/html

ServerName www.httpdtest.com

ErrorLog logs/httpdtest.com-error_log

CustomLog logs/httpdtest.com-access_log common

</VirtualHost> 

<VirtualHost 192.168.10.10:8080>

DocumentRoot /data/web/baidu

ServerName www.baidu.com

ErrorLog logs/baidu.com-error_log

CustomLog logs/baidu.com-access_log common

</VirtualHost>

<VirtualHost 192.168.10.10:8081>

DocumentRoot /data/web/google

ServerName www.google.com

ErrorLog logs/google.com-error_log

CustomLog logs/google.com-access_log common

</VirtualHost>

4.启动服务

[root@localhost ~]#service httpd restart


5.测试

http://www.httpdtest.com:80

http://www.baidu.com:8080

http://www.google.com:8081


你可能感兴趣的:(httpd,配置实验)