Aginx网站维护

apache    HTTP

 

 

 

httpd基础网站服务

httpd访问控制

AWStats日志分析

虚拟Web主机

###############################

                            spacer.gif

安装软件包:

spacer.gif [root@svr5 ~]# yum -y install httpdhttpd-manual

主要目录和文件

    主配置文件:/etc/httpd/conf/httpd.conf

    子配置目录:/etc/httpd/conf.d/

    网站根目录:/var/www/html/

    访问日志:/var/log/httpd/access_log

错误日志:/var/log/httpd/error_log

spacer.gif

练习一:基本网站部署

spacer.gif1. 配置启动httpd服务

[root@svr5~]# cp  /etc/httpd/conf/httpd.conf{,.bak}

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

ServerName  svr5.tarena.com

 

[root@svr5~]# service httpd start

[root@svr5~]# netstat -anpt | grep httpd

 

** 红帽欢迎页的生效机制

/etc/httpd/conf/httpd.conf  -->Include --> conf.d/welcome.conf

-->/error/noindex.html

 

2. 部署网页文档

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

[root@svr5html]# vim index.html

[root@svr5html]# unzip /root/Desktop/test_web.zip

[root@svr5html]# ls

index.html  jiajutiyan sirbiz

 

3. 浏览器访问

    http://服务器地址/

    http://服务器地址/jiajutiyan/

http://服务器地址/sirbiz/

spacer.gif

spacer.gif练习二:httpd常见配置

1)网站迁移到/var/ftp

    DocumentRoot "/var/ftp"

   <Directory "/var/ftp">

2)设置首页  DirectoryIndex

    支持 index.php index.html index.htm

 

                                                                                                                         FQDN====       主机名.域名

spacer.gifspacer.gif

spacer.gifspacer.gif

spacer.gif

练习三:禁止使用符号链接

服务器:ln  -s /  /var/ftp/system

浏览器访问:http://服务器地址/system 【查看服务器根目录】

—— 需求:禁止此项功能

 

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

<Directory"目录路径">

     Opitons -FollowSymlinks

     .. ..

</Directory>

[root@svr5~]# service httpd restart

 

练习四:禁止使用自动索引

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

<Directory"目录路径">

     Opitons -Indexes

     .. ..

</Directory>

[root@svr5~]# service httpd restart

 

 

练习五:使用目录别名

1)当访问 http://服务器地址/doc/

         实际网页存放在 /var/www/manual/

2)当访问 http://服务器地址/tools

         实际网页存放在 /usr/src

 

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

Alias/doc/ "/var/www/manual/"

Alias/tools "/usr/src"

....

[root@svr5~]# service httpd restart

 

spacer.gif

 

练习六(选作):客户机访问控制

1.允许从任何地址访问

<Directory  /var/www/html>

    Order allow,deny

    Allow from  all

</Directory>

 

2. 仅允许从个别网段、IP地址访问

<Directory  /var/www/html>

    Order allow,deny

    Allow from  192.168.4.0/24  192.168.7.200

</Directory>

 

权限

Options–Indexes(控制索引)     -FollowSymLinks(控制链接符号)

目录权限

客户机地址

spacer.gifspacer.gif

用户授权

spacer.gifspacer.gif

allowoverridenone(不允许)                   允许覆盖

 

.htaccess默认 权限文件

 

 

 

 

练习七:为指定目录启用用户授权

1)在网站根目录下建一个子目录nsd1403

     能访问 http://服务器地址/nsd1403/

2)给nsd1403添加用户授权,只允许用户stu01访问(密码123456

 

[root@svr5~]# htpasswd -c /etc/httpd/authpwd stu01

....

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

<Directory  "/var/ftp/nsd1403">

    AuthName "Tarena Library."                             认证领域名称,用于弹窗提示

    AuthType basic                                                     认证类型.一般 basic

    AuthUserFile /etc/httpd/authpwd                用户数据文件路径

    Require valid-user                                                用户定义名单

    #Require user stu01                                             指定授权用户或组

</Directory>

[root@svr5~]# service httpd restart

 

spacer.gifspacer.gif

spacer.gif

 

**httpd两种工作模式

prefork方式:预创建、非线程模式,2.2.x 系列默认

worker方式:多线程、多处理模式

 

spacer.gif

spacer.gif

spacer.gif

 

练习八:构建AWStats日志分析系统

1. 安装awstats软件包

[root@svr5pub]# tar  zxf  awstats-7.1.tar.gz

[root@svr5pub]# mv  awstats-7.1  /usr/local/awstats

 

2. 为要统计的站点建立配置文件

[root@svr5pub]# cd  /usr/local/awstats/tools/

[root@svr5tools]# ./awstats_configure.pl

>/etc/httpd/conf/httpd.conf    //指定Web配置路径

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

>svr5.tarena.com                  //指定网站名称

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

                         ……  自动重启httpd服务

>                       //回车,继续

>                       //回车,完成配置

 

3. 修改站点统计配置文件

[root@svr5tools]# vim /etc/awstats/awstats.svr5.tarena.com.conf

LogFile="/var/log/httpd/access_log"         //要分析的日志文件

 

[root@svr5tools]# mkdir  /var/lib/awstats

 

4. 执行日志分析,并设置cron计划任务

[root@svr5tools]# ./awstats_updateall.pl  now

....

[root@svr5tools]# crontab  -e

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

 

5. 查看分析结果

http://服务器地址/awstats/awstats.pl?config=配置名称

 

[root@svr5~]# vim /网站根目录下/aw-svr5.html

<html>  <head>

<metahttp-equiv=refresh content="0;

url=http://服务器地址/awstats/awstats.pl?config=配置名称">

</head>

<body></body>  </html>

 

访问http://服务器地址/aw-svr5.html

 

 

练习九:基于域名的虚拟主机

1www.google.com --> 192.168.4.5

    网页显示:GOOGLE

2www.baidu.com --> 192.168.4.5

    网页显示:BAIDU

spacer.gif spacer.gif

spacer.gif spacer.gif

spacer.gif spacer.gif

1www.google.com --> 192.168.4.5

    网页显示:GOOGLE

2www.baidu.com --> 192.168.4.5

    网页显示:BAIDU

 

1. 解决域名解析的文件所有客户端)

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

192.168.4.5     www.google.com www.baidu.com

 

2. 准备网页文档

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

[root@svr5 html]#mkdir google baidu

[root@svr5 html]#echo "GOOGLE" > google/index.html

[root@svr5 html]#echo "BAIDU" > baidu/index.html

 

3. 修改httpd服务配置

[root@svr5 html]#cd /etc/httpd/conf.d/

[root@svr5conf.d]# vim vhosts.conf

NameVirtualHost192.168.4.5

<VirtualHost192.168.4.5>

        ServerName www.google.com

        DocumentRoot"/var/www/html/google"

</VirtualHost>

<VirtualHost192.168.4.5>

        ServerName www.baidu.com

        DocumentRoot"/var/www/html/baidu"

</VirtualHost>

 

[root@svr5conf.d]# grep ^Include /etc/httpd/conf/httpd.conf

Includeconf.d/*.conf

 

[root@svr5conf.d]# service httpd restart

 

 

 

 

练习十(选作):基于IP地址的虚拟主机

1www.sina.com --> 192.168.4.5

    网页显示:XINLANG

2www.sohu.com --> 192.168.40.5

    网页显示:SOUHU

spacer.gif spacer.gif

 

 

练习十一(选作):基于端口的虚拟主机

1www.sina.com --> 192.168.4.5:80

    网页显示:新浪前台

2www.sina.com --> 192.168.4.5:81

网页显示:新浪管理后台

 

spacer.gifspacer.gif

 

 

 

#####################################

elinks              –dump             网址

 

 

软件包: httpd

主配置文件/etc/httpd/conf/httpd.conf

 

 

端口 TCP 80

 

serverRoot    /etc/httpd/服务根目录

Documenroot          网页根目录

directoryindex         指定默认首页文件

 

Alias/别名目录实际目录路径

 

 

<Dirctory 目录路径”>

 

orderallow,deny

allowfrom all

AutheTypebasic

AuthName“提示信息

AuthUserFile“用户帐号文件路径

Requireuser 用户1 用户2

 

</Dirctory>

 

htpasswd   -c (第一次使用加-c) 账户文件路径 用户名

 

AWStats日志分析系统

        

 

操作对象:指定的网站访问日志 accesss_log

安装目录:/usr/local/awstats

配置工具:安装目录/tools/awstats_configure.pl

分析工具:安装目录/tools/awstats_updateall.pl

配置目录:/etc/awstats/awstats.网站名称.conf

 

虚拟Web主机

基于域名

 

NameVirtualHost服务器IP地址

<VirtualHost服务器IP地址>

ServerName网站的FQDN名称

DocumentRoot网站根目录1

</Virtualhost>

 

<VirtualHost服务器IP地址>

ServerName网站的FQDN名称

DocumentRoot网站根目录2

</Virtualhost>

 

<VirtualHost服务器IP地址>

ServerName192.168.4.5

DocumentRoot网站根目录3

</Virtualhost>