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

【初学菜鸟作--HTTP服务的安装及相关配置】

时间:2014-06-17 17:12:47      阅读:371      评论:0      收藏:0      [点我收藏+]

标签:http httpd apache

HTTP服务的安装及相关配置

实验目的:对HTTP服务进行安装配置,以达到访问目的及访问权限控制

实验准备:安装有apache软件的服务端(192.168.1.1

                 客户机1192.168.1.2)客户2192.168.1.3

保证客户机与服务端的连通

实验一:服务端的基本配置与HTTP服务的安装,初始浏览

  1. 1.     服务端的基本配置

Ip配置:

[root@localhost~]# ifconfig eth0 | head -2 |tail -1

Inetaddr:192.168.1.  Bcast:192.168.1.255Mask:255.255.255.0

主机名配置:

[root@localhost~]# tail -1 /etc/sysconfig/network

HOSTNAME=web01.tarena.com

修改hosts文件,增加域名指向:

[root@localhost ~]# cat /etc/hosts | tail -2

192.168.1.1     web01.tarena.com web01

  1. 192.168.1.1     www.tarena.comweb01

  2. 2.     HTTP服务的安装

服务端的安装

通过yum库安装http服务

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

启动服务

[root@localhostconf]# servicehttpd restart

[root@localhostconf]#chkconfighttpd on

通过浏览器访问本地地址看查看默认页

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

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

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

开启保持连接

确认默认httpd是否支持php 

  1. 1.备份主配置文件,以防出错

[root@localhost~]# cp/etc/httpd/conf/httpd.confhttpd.conf.bak

  1. 2.修改主配置文件,实现实验要求

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

74 KeepAliveON    --开启保持连接默认为OFF

265 ServerNamewww.tarena.com:80  --本站点名称

#ServerNamewww.example.com:80    --默认名称为注释

391 DirectoryIndex index.html index.php–-更改默认首页包括html,php

DirectoryIndexindex.html index.html.var  --默认索引页/首页文件

保存退出后重启服务

[root@localhostconf]# servicehttpd restart

[root@localhostconf]#chkconfighttpd on

3.在网站根目录(/var/www/html)下创建.html文件并在客户端访问测试

[root@localhost~]# cd /var/www/html

[root@localhosthtml]# touch index.html

[root@localhosthtml]# vim index.html

[root@localhosthtml]# cat index.html

<html>

<body>haha</body>        访问测试页内容为haha

</html>

   服务端测试结果如下图

bubuko.com,布布扣

在网站根目录下编写php页面并测试

[root@localhost html]#touchtest.php

[root@localhost html]#cattest.php

<?php

phpinfo()

?>

进入客户机登录http://www.tarena.com/test.php进行测试(默认php服务未安装)

实验三:

配置只允许客户机192.168.1.2访问

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

  1. 1.进入主配置文件修改,以达到控制访问目的

306 <Directory"/var/www/html">指定目录

332     Order allow,deny       访问权限

333 #   Allow from all      允许所有访问,默认

334     Allow from 192.168.1.2  允许访问地址(生效)

335</Directory>

保存退出后重启服务,进入客户机1,2分别测试

客户机1(192.168.1.2)可以访问www.tarena.com

bubuko.com,布布扣

客户机2(192.168.1.3)没有访问权限

bubuko.com,布布扣

  1. 2.进入主配置文件增加访问控制条目,以达到允许所有用户访问www.tarena.com/authdir/index.html的目的

在服务端网站根目录下新建站点authdir并创建index.html测试页面

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

[root@localhosthtml ]#touch/var/www/html/authdir/index.html

[root@localhost html]#catauthdir/index.html

天空之城

进入主配置文件增加访问控制条目

337 <Directory/var/www/html/authdir>  指定目录

338         Order allow,deny

339         Allow from all

340 </Directory>

保存退出重启后进入客户端进入www.tarena.com/authdir测试

bubuko.com,布布扣

测试可得客户机1,2都可以登录到www.tarena.com/authdir看到测试内容

试验四:HTTP的用户授权

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

  1. 1.进入主配置文件在authdir下设置访问控制权限

337 <Directory /var/www/html/authdir>  指定目录

338         Order allow,deny

339         Allow from all           

340         AuthName "PleaseInput Password!!"    

页面提示

341         AuthType Basic     认证类型,一般为基本

342         AuthUserFile"/etc/httpd/.vuser"

            登录账户密码所在位置

343         Require valid-user指定授权用户

344 </Directory>

保存后退出并重启服务

  1. 2.新建允许登录账户密码并指定存放位置/etc/httpd/.vuser

[root@localhost html]# htpasswd-c /etc/httpd/.vuser admin(允许登录用户)

New password:

Re-type new password:

Adding password for user admin

[root@localhost html]# cat/etc/httpd/.vuser

admin:UX8W9njqYtbUc

  1. 3.进入客户机测试

bubuko.com,布布扣

测试证明访问控制生效,需要输入账号用户名才可登录

实验五:HTTP目录别名

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

1.创建/var/www/html/sina.com/bbs目录并在其内创建测试页面

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

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

<html>

<head><title>Thisis a test Page!!!</title>

<body>

<h1>This is bbs.sina.comtest Page!!!</h1>

</body>

</head>

</html>

  1. 2.在主配置文件中增加/var/www/html/sina.com/bbs的别名/sina

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

  1. 3.从客户端登录www.tarena.com/sina测试

bubuko.com,布布扣

实验六:

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

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

  1. 1.查看默认HTTP使用的进程管理方式(管理方式分为prefork,worker)

Prefork

<IfModuleprefork.c>

StartServers       8 启动服务时创建的进程数

MinSpareServers    5 最少空闲进程数

MaxSpareServers   20 最多空闲进程数

ServerLimit      256 最大客户端上限

MaxClients       256 最多进程数,小于等于上值

MaxRequestsPerChild  4000  每个进程最多处理的请求

</IfModule>

Worker

<IfModuleworker.c>

StartServers         2  启动服务时创建的进程数

MaxClients         150    最多线程数,应小于ServerLimit

MinSpareThreads     25    最少空闲线程数

MaxSpareThreads     75    最多空闲线程数

ThreadsPerChild     25    每个进程可提供的线程数

MaxRequestsPerChild  0    每个进程最多处理的请求数

</IfModule>

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

[root@localhost ~]# httpd -l

Compiled in modules:        

core.c

prefork.c

http_core.c

mod_so.c

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

[root@localhostsbin]#mvhttpdhttpd.prefork

[root@localhostsbin]#mvhttpd.workerhttpd

[root@localhostsbin]#servicehttpd restart

[root@localhostsbin]# httpd -l

Compiled in modules:

core.c

worker.c

http_core.c

mod_so.c

试验七:

部署Awstats统计Http访问日志

配置Awstats(建立在HTTP基础上的访问日志统计软件)

1.将准备好的压缩包解压到/usr/local,并进入解压到的目录

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

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

2.将解压完的目录改名为awstats,进入其目录下的tools并启动awstats_configure.pl进行配置

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

因为在配置过程中将会在httpd主配置文件中生成<Directory"/usr/local/awstats/wwwroot">权限列表,如不改名将与目录不符,不能生效

[root@localhost local]# cdawstats/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 configfile ?

Do you want me to build a new AWStatsconfig/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...        回车

3.修改主配置文件

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

LogFile="/var/log/httpd/access_log"    指定提取成功访问的日志位置

4.创建awstats日志存放位置

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

   启动服务

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

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

[root@localhost tools]# servicehttpd restart

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

5.进入客户端登录http://www.tarena.com/awstats/awstats.pl?config=www.tarena.com进行测试

bubuko.com,布布扣

6.如要定时刷新可配置计划任务

[root@localhost tools]# crontab –e

[root@localhost tools]# crontab -l

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

[root@localhost tools]# servicecrond restart

[root@localhost tools]# chkconfigcrond on

7.可通过html代码实现网页跳转功能,获得简洁域名就能访问

[root@localhost tools]# cat /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服务的安装及相关配置】,布布扣,bubuko.com

【初学菜鸟作--HTTP服务的安装及相关配置】

标签:http httpd apache

原文地址:http://yeyue.blog.51cto.com/9037000/1427087

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