码迷,mamicode.com
首页 > 其他好文 > 详细

apache

时间:2014-06-17 17:50:22      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:apache

实验拓扑:

         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

前提条件

 

1ip

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

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

HWADDR=00:0c:29:b3:05:f6

IPADDR=192.168.4.1

NETMASK=255.255.255.0

主机名

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

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=qhp.tarena.com

GATEWAY=192.168.4.254

hosts文件

[root@qhp ~]# vim /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1               localhost.localdomain localhost

::1             localhost6.localdomain6 localhost6

192.168.4.1             www.tarena.com www

192.168.4.1             qhp.tarena.com qhp

 

[root@qhp ~]# service network restart

正在关闭接口 eth0:                                        [确定]

关闭环回接口:                                             [确定]

弹出环回接口:                                             [确定]

弹出界面 eth0:                                            [确定]

 [root@qhp ~]# chkconfig network on

安装软件

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

5、启动服务

[root@qhp ~]# service httpd restart

[root@qhp ~]# chkconfig httpd on

 

[root@qhp ~]# rpm -ql httpd

/etc/httpd

/etc/httpd/conf

/etc/httpd/conf.d

/etc/httpd/conf.d/welcome.conf

/etc/httpd/conf/httpd.conf

...

 

 

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

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

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

开启保持连接

确认默认httpd是否支持php

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

 

服务器:

 

1、备份

[root@qhp ~]# cd /etc/httpd/conf

[root@qhp conf]# cp httpd.conf httpd.conf.bak

[root@qhp conf]# ls

httpd.conf  httpd.conf.bak  magic

 

2、配置

[root@qhp conf]# vim /etc/httpd/conf/httpd.conf

...

74 KeepAlive On

...

265 ServerName www.tarena.com:80

...

391 DirectoryIndex index.html index.php

...

3、启动服务

[root@qhp ~]# cd /etc/httpd/conf

[root@qhp conf]# cp httpd.conf httpd.conf.bak

[root@qhp conf]# ls

httpd.conf  httpd.conf.bak  magic

[root@qhp conf]# vim /etc/httpd/conf/httpd.conf

[root@qhp conf]# service httpd restart

停止 httpd:                                               [失败]

启动 httpd:                                               [确定]

[root@qhp conf]# service httpd restart

停止 httpd:                                               [确定]

启动 httpd:                                               [确定]

[root@qhp conf]# chkconfig httpd on

 

 [root@qhp conf]# cd

[root@qhp ~]# cd Desktop/

[root@qhp Desktop]# ls

ApacheMenu-2.2.zip  test_web.zip

[root@qhp Desktop]# unzip test_web.zip

[root@qhp Desktop]# mv jiajutiyan/* /var/www/html/

4、编写测试php页面

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

<?php

        phpinfo();

?>

 

客户端

[root@ qhp ~]# vim /etc/hosts

192.168.4.1             www.tarena.com  www

[root@ qhp ~]# firefox

 

http://www.tarena.com

bubuko.com,布布扣 

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

bubuko.com,布布扣 

 

实验三:

  1、仅允许192.168.4.21访问

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

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

 

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

 

332     Order allow,deny

333 #    Allow from all

334         Allow from 192.168.4.21

335 </Directory>

[root@qhp ~]# service httpd restart

192.168.4.21

bubuko.com,布布扣 

192.168.4.20

bubuko.com,布布扣 

 

2、新建authdir站点

 

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

[root@qhp ~]# echo "sdfkhaf ivyhijlmkdfvndfhdckdfh98ec" > /var/www/html/authdir/index.html

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

 

336  <Directory /var/www/html/authdir>

337          Order allow,deny

338          Allow from all

339  </Directory>

 

linux

bubuko.com,布布扣 

win7

bubuko.com,布布扣 

[root@qhp ~]# tail -n 5 /var/log/httpd/error_log 

[Mon Jun 16 19:37:20 2014] [notice] caught SIGTERM, shutting down

[Mon Jun 16 19:37:20 2014] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)

[Mon Jun 16 19:37:20 2014] [notice] Digest: generating secret for digest authentication ...

[Mon Jun 16 19:37:20 2014] [notice] Digest: done

[Mon Jun 16 19:37:20 2014] [notice] Apache/2.2.3 (Red Hat) configured -- resuming normal operations

 

试验四:HTTP的用户授权

客户端访问http://www.tarena.com/authdir需要输入用户名密码

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

336  <Directory /var/www/html/authdir>

337          Order allow,deny

338          Allow from all

339          AuthName "Please Input Password!!"

340          AuthType Basic

341          AuthUserFile "/etc/httpd/.vuser"

342          Require valid-user

343  </Directory>

 

2、创建账户密码

[root@ qhp ~]# htpasswd -c /etc/httpd/.vuser admin

New password: 

Re-type new password: 

Adding password for user admin

[root@ qhp ~]# service httpd restart

 

bubuko.com,布布扣 

实验五:HTTP目录别名

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

1、创建测试站点

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

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

<html>

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

<body>

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

</body>

</html>

2、修改主配置文件

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

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

3、启动服务测试

[root@ qhp ~]# service httpd restart

http://www.tarena.com/sina

 

bubuko.com,布布扣 

 

实验六:

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

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

[root@qhp ~]# httpd -l

Compiled in modules:

  core.c

  prefork.c

  http_core.c

  mod_so.c

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

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

[root@qhp sbin]# mv httpd.worker httpd

[root@qhp sbin]# !ser

service httpd restart

停止 httpd:                                               [确定]

启动 httpd:                                               [确定]

[root@qhp sbin]# httpd -l

Compiled in modules:

  core.c

  worker.c

  http_core.c

  mod_so.c

 

试验七:

部署Awstats统计Http访问日志

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

 

[root@qhp ~]# 

[root@qhp ~]# cd Desktop/

[root@qhp Desktop]# tar -zxf awstats-7.1.tar.gz -C /usr/local/

[root@qhp Desktop]# cd /usr/local/

[root@qhp local]# ls

awstats-7.1  etc    include  lib64    sbin   src

bin          games  lib      libexec  share

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

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

[root@qhp tools]# ./awstats_configure.pl

 

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

> /etc/httpd/conf/httpd.conf

 

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

file (required if first install) [y/N] ? y

 

Your web site, virtual server or profile name:

> www.tarena.com

 

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@qhp tools]# vim /etc/awstats/awstats.www.tarena.com.conf

51 #LogFile="/var/log/httpd/mylog.log"

52 LogFile="/var/log/httpd/access_log"

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

3、将日志文件导入Awstats

[root@qhp tools]# ./awstats_updateall.pl now

Running ‘"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.tarena.com -configdir="/etc/awstats"‘ to update config www.tarena.com

Create/Update database for config "/etc/awstats/awstats.www.tarena.com.conf" by AWStats version 7.0 (build 1.975)

From data in log file "/var/log/httpd/access_log"...

Phase 1 : First bypass old records, searching new record...

Searching new records from beginning of log file...

Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...

Jumped lines in file: 0

Parsed lines in file: 89

 Found 0 dropped records,

 Found 0 comments,

 Found 0 blank records,

 Found 0 corrupted records,

 Found 0 old records,

 Found 89 new qualified records.

 

[root@qhp tools]# crontab -e

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

 

[root@qhp tools]# service crond restart

停止 crond:                                               [确定]

启动 crond:                                               [确定]

[root@qhp tools]# chkconfig crond on

4、验证

http://www.tarena.com/awstats/awstats.pl?config=www.tarena.com

bubuko.com,布布扣 

 

网页跳转

[root@qhp 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

本文出自 “一饮寂寞” 博客,转载请与作者联系!

apache,布布扣,bubuko.com

apache

标签:apache

原文地址:http://lowlife.blog.51cto.com/9042241/1427086

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!