HTTP服务器搭建学习练习

 HTTP服务器搭建实验报告

实验拓扑:

         Linux Client

-----RHEL5.9vmnet1----------vmnet1

         Win7 Client


实验一:查看默认HTTP配置

找到默认红帽欢迎页面

/etc/httpd/conf/httpd.conf ---->Include ----> /etc/httpd/conf.d  ----> welcome.conf  ----> /var/www/error/noindex.html


实验步骤:


1.配置ip 保证客户机与服务器在同一网段上并能ping 

 HTTP服务器ip  192.168.10.250   客户机ip 192.168.10.50

HTTP 名称 vsftpser.tarena.com

客户机名称 WIN

[root@vsftpser ~]# ping 192.168.10.10

PING 192.168.10.50 (192.168.10.50) 56(84) bytes of data.

64 bytes from 192.168.10.50: icmp_seq=1 ttl=64 time=1.70 ms

64 bytes from 192.168.10.50: icmp_seq=2 ttl=64 time=0.228 ms

64 bytes from 192.168.10.50: icmp_seq=3 ttl=64 time=0.217 ms

64 bytes from 192.168.10.50: icmp_seq=4 ttl=64 time=0.235 ms


注:1)实验过程中出现WIN7客户机可以ping通主机和自身,但是服务器无法ping通客户机    ――――》解决方法,查看防火墙开启情况,关闭防火墙,实现互通。



2.配置主机名及修改主机名并开启网关

[root@vsftpser ~]# cat /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=web01.tarena.com

GATEWAY=192.168.10.254                        //修改主机名

[root@vsftpser ~]# vim /etc/hosts                 //修改主机配置文件参数

      192.168.10.250   www.tarena.com   www    //添加该条确保客户机能访问网页

[root@vsftpser ~]# service network restart

#chkconfig network on             //开启服务


 3.安装软件

 # yum -y install httpd

Loaded plugins: product-id, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Setting up Install Process

No package httpd available.

Nothing to do                    //表明该服务器没有安装yum库 


1)配置yum 

   root@vsftpser ~]# cd /etc/yum.repos.d/

[root@vsftpser yum.repos.d]# vim rhel-debuginfo.repo

[yanhao.respo]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///misc/cd/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

#yum �Cy install httpd   // 安装httpd服务

Installed:

  httpd.x86_64 0:2.2.3-74.el5                                                   


Dependency Installed:

  apr.x86_64 0:1.2.7-11.el5_6.5             apr-util.x86_64 0:1.2.7-11.el5_5.2  

  postgresql-libs.x86_64 0:8.1.23-6.el5_8  


Complete!


5、启动服务

[root@localhost ~]# service httpd restart

[root@localhost ~]# chkconfig httpd on

[root@vsftpser ~]# service httpd restart   // 设计服务开机自启动

停止 httpd:                                               [失败]

启动 httpdhttpd: apr_sockaddr_info_get() failed for vsftpser.tarena.com

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [确定]


注: 失败的原因是 /etc/httpd/conf/httpd.conf  文件中ServiceName 中域名没有192.168.10.250所有应的域名 

   修改# vim /etc/httpd/conf/httpd.conf 


#ServerName www.example.com:80

ServerName www.tarena.com:80      //添加该条域名解释  


正常启动


试验二:基本HTTP服务器的配置

Web服务器域名:www.tarena.com

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

开启保持连接

确认默认httpd是否支持php

网站用老师提供的test_web.zip测试


服务器操作:

1、备份主配置文件


[root@localhost ~]# cd /etc/httpd/conf   //进入主配置文件目录

[root@localhost conf]# cp httpd.conf httpd.conf.bak //备份配置文件防

2.修改配置文件

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

...

 74 KeepAlive On        //保持连接 

...

267 ServerName www.tarena.com:80     //服务器域名

...

394DirectoryIndex index.html index.php    //默认首页



3、启动服务

[root@localhost ~]# service httpd restart   //重启服务

[root@localhost ~]# chkconfig httpd on

[root@localhost ~]# cd /root/Desktop/

[root@localhost Desktop]# unzip test_web.zip   //解压测试文件

[root@localhost Desktop]# mv jiajutiyan/* /var/www/html/   //将测试网站移到默认文件夹下

4、编写测试php页面

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

<?php

        phpinfo();

?>

5

测试:

1、在客户端hosts文件指定

192.168.10.250www.tarena.comwww

2、打开浏览器

http://www.tarena.com   

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

在浏览器中输入www.tarena.com 出现测试网站的主页说明设置成功

访问php显示文件内容,表示默认不支持php


实验结果出现:测试文件的页面 以及php 页面


  实验五: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 ~]# vim  /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、修改主配置文件

[2、修改主配置文件

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf  //修改主配置文件 

Alias /sina     "/var/www/html/sina.com/bbs"  //全局配置添加别名语句

3、启动服务测试

[root@ser1 ~]# service httpd restart  // 重启服务

http://www.tarena.com/sina    // WIN网页上输入该网址显示:


win7客户机测试访问http://www.tarena.com/sina显示

This is bbs.sina.com 


test Page!!!    设置成功


实验六:

查看默认HTTP使用进程管理方式

更改默认进程管理方式为worker模式

[root@localhost ~]# httpd -l 

Compiled in modules:

  core.c

  prefork.c    //系统默认为进程控制模式

  http_core.c

  mod_so.c

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

[root@localhost sbin]# mv httpd httpd.prefork

[root@localhost sbin]# mv httpd.worker httpd     //切换模式

[root@localhost sbin]# service httpd restart

[root@localhost sbin]# httpd -l

Compiled in modules:

  core.c

  worker.c       //更换成功

  http_core.c

  mod_so.c


注:如果想再从worker模式切换则可以执行以下程序


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

[root@localhost sbin]# mv httpd http.worker

[root@localhost sbin]# mv httpd.preforx  httpd

[root@localhost sbin]# service httpd restart

[root@localhost sbin]# httpd �Cl   即可



试验七:

部署Awstats统计Http访问日志

1、安装软件(软件在/usr/src下)

[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            //将文件移动到local 下改名

[root@localhost local]# cd awstats/tools/

[root@localhost tools]# ./awstats_configure.pl        //运行文件

...

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

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

...

-----> Need to create a new config file ?

Do you want me to build a new AWStats config/profile

file (required if first install) [y/N] ? y   //生成awstats的配置文件

...

Your web site, virtual server or profile name:

> www.tarena.com            //输入你的web服务器名字

...

Default: /etc/awstats

Directory path to store config file(s) (Enter for default):

...

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

Press ENTER to continue... 

...

Press ENTER to finish...

2、修改主配置文件

[root@localhost tools]# vim /etc/awstats/awstats.www.tarena.com.conf   // 编辑配置文件

...

  51 LogFile="/var/log/httpd/access_log"       //修改日志文件


[root@localhost tools]# mkdir /var/lib/awstats      // 创建文件夹

3、将日志文件导入Awstats

[root@localhost tools]# ./awstats_updateall.pl now   //运行文件

[root@localhost tools]# crontab �Ce      //  设置日志轮转

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

[root@localhost tools]# service crond restart

[root@localhost tools]# chkconfig crond on

4、验证:

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

[root@localhost tools]# vim  /var/www/html/awstats.html   // 设置网页

<html>

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

</head>

<body>

</body>

</html>

验证:

http://www.tarena.com/awstats.html

. 浏览器访问http://www.tarena.com/awstats.html 显示统计信息为设置成功



本文出自 “奋斗从我开始” 博客,谢绝转载!

你可能感兴趣的:(http,服务器,搭建)