Apache與AWStats

來源:互聯網
上載者:User

標籤:

一、           實驗步驟及結果

第一階段

                                                 搭建Apache網站服務

 

Hstname

OS

IP

Software

www.benet.com

 

CentOS-6.5

192.168.1.200

httpd-2.2.17.tar.gz

awstats-7.0.zip

Client

Windows 7

192.168.1.234

IE

 

關閉防火牆:service iptables stop

配置Apache服務

[[email protected] /]# tar zxvf httpd-2.2.17.tar.gz -C /usr/src/

[[email protected] /]# unzip awstats-7.0.zip

[[email protected] /]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install

--prefix:指定安裝目錄

--enable-so:啟用動態載入模組支援

--enable-rewrite:啟用網站重寫功能

--enable-charset-lite:啟動字元集支援

--enable-cgi:啟用CGI指令碼程式支援

[[email protected] httpd-2.2.17]# ln -s /usr/local/httpd/bin/* /usr/local/bin/               //最佳化執行路徑

[[email protected] ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

 [[email protected] ~]# vim /etc/init.d/httpd

#chkconfig: 35 85 15

#description: Apache HTTP Server

[[email protected] ~]# chkconfig --add httpd

[[email protected] ~]# chkconfig --level 35 httpd on

[[email protected] ~]# vim /usr/local/httpd/conf/httpd.conf

ServerName www.benet.com:80                               //添加網站網域名稱

[[email protected] ~]# httpd –t                                                //檢查設定檔錯誤

Syntax OK

[[email protected] ~]# /etc/init.d/httpd start

[[email protected] ~]# netstat -anpt |grep 80

tcp        0      0 :::80                       :::*                        LISTEN      54881/httpd

[[email protected] ~]# elinks http://192.168.1.200

It works!

 

基於不同的網域名稱建立虛擬Web主機

為兩個網站建立網站的文檔目錄

[[email protected] ~]# mkdir /usr/local/httpd/htdocs/benetcom

[[email protected] ~]# mkdir /usr/local/httpd/htdocs/accpcom

[[email protected] ~]# echo ‘<h1>www.benet.com</h1>‘ > /usr/local/httpd/htdocs/benetcom/index.html

[[email protected] ~]# echo ‘<h1>www.accp.com</h1>‘ > /usr/local/httpd/htdocs/accpcom/index.html

修改設定檔httpd.conf和httpd-vhosts.conf

[[email protected] ~]# cd /usr/local/httpd/conf/extra/

[[email protected] extra]# vim httpd-vhosts.conf

NameVirtualHost 192.168.1.200:80

 

<VirtualHost 192.168.1.200:80>

    DocumentRoot "/usr/local/httpd/htdocs/benetcom/"

    ServerName www.benet.com

    ErrorLog "logs/www.benet.com-error_log"

    CustomLog "logs/www.benet.com-access_log" common

</VirtualHost>

 

<VirtualHost 192.168.1.200:80>

    DocumentRoot "/usr/local/httpd/htdocs/accpcom/"

    ServerName www.accp.com

    ErrorLog "logs/www.accp.com-error_log"

    CustomLog "logs/www.accp.com-access_log" common

</VirtualHost>

[[email protected] extra]# cd ..

[[email protected] conf]# vim httpd.conf

Include conf/extra/httpd-vhosts.conf                          //將此行前面的"#"去掉

[[email protected] ~]# vim /etc/hosts

192.168.1.200   www.benet.com www.accp.com

[[email protected] ~]# /etc/init.d/httpd restart

[[email protected] ~]# elinks http://www.benet.com

www.benet.com

[[email protected] ~]# elinks http://www.accp.com

www.accp.com

      

第二階段

部署安裝awstats日誌分析系統

[[email protected] /]# unzip awstats-7.0.zip

[[email protected] /]# mv awstats-7.0 /usr/local/awstats

[[email protected] /]# cd /usr/local/awstats/tools/

[[email protected] tools]# ./awstats_configure.pl

 

----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----

This tool will help you to configure AWStats to analyze statistics for

  • one web server. You can try to use it to let it do all that is possible

in AWStats setup, however following the step by step manual setup

documentation (docs/index.html) is often a better idea. Above all if:

- You are not an administrator user,

- You want to analyze downloaded log files without web server,

- You want to analyze mail or ftp log files instead of web log files,

- You need to analyze load balanced servers log files,

- You want to ‘understand‘ all possible ways to use AWStats...

Read the AWStats documentation (docs/index.html).

 

-----> Running OS detected: Linux, BSD or Unix

 

-----> Check for web server install

 

Enter full config file path of your Web server.

Example: /etc/httpd/httpd.conf

Example: /usr/local/apache2/conf/httpd.conf

Example: c:\Program files\apache group\apache\conf\httpd.conf

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

> /usr/local/httpd/conf/httpd.conf                       //httpd主設定檔路徑

 

-----> Check and complete web server config file ‘/usr/local/httpd/conf/httpd.conf‘

Warning: You Apache config file contains directives to write ‘common‘ log files

This means that some features can‘t work (os, browsers and keywords detection).

Do you want me to setup Apache to write ‘combined‘ log files [y/N] ? y           //設定記錄檔類型

  Add ‘Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"‘

  Add ‘Alias /awstatscss "/usr/local/awstats/wwwroot/css/"‘

  Add ‘Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"‘

  Add ‘ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"‘

  Add ‘<Directory>‘ directive

  AWStats directives added to Apache config file.

 

-----> Update model config file ‘/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf‘

  File awstats.model.conf updated.

 

-----> 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                               //佈建網站設定檔

 

-----> Define config file name to create

What is the name of your web site or profile analysis ?

Example: www.mysite.com

Example: demo

Your web site, virtual server or profile name:

> www.benet.com                                                          //統計的網站名稱

往後預設配置按斷行符號

 

修改awstats.www.benet.com.conf設定檔

[[email protected] ~]# mkdir /var/lib/awstats

[[email protected] ~]# vim /etc/awstats/awstats.www.benet.com.conf

LogFile="/usr/local/httpd/logs/access_log"

DirData="/var/lib/awstats"

建立資料庫的存放目錄,並更新資料庫

[[email protected] ~]# /usr/local/awstats/tools/awstats_updateall.pl now                   //執行更新指令碼

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

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

From data in log file "/usr/local/httpd/logs/access_log"...

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

Searching new records from beginning of log file...

Jumped lines in file: 0

Parsed lines in file: 2

 Found 0 dropped records,

 Found 0 comments,

 Found 0 blank records,

 Found 2 corrupted records,

 Found 0 old records,

       Found 0 new qualified records.

建立周期性計劃任務

[[email protected] ~]# crontab -e

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

建立網站跳轉頁

[[email protected] /] vim aws.html

<html>

<head>

<meta http-equiv=refresh content="0;

url=http://www.benet.com/awstats/awstats.pl?config=www.benet.com">

</head>

<body><body>

</html>

[[email protected] /]# mv aws.html /usr/local/httpd/htdocs/         //將跳轉頁移動到網站根目錄下

[[email protected] ~]# /etc/init.d/httpd restart

重啟apache訪問awstats首頁

 

第三階段

為AWSstats進行存取權限的控制

客戶機地址限制

[[email protected] /]# vim /usr/local/httpd/conf/httpd.conf

<Directory "/usr/local/awstats/wwwroot">

    Options None

    AllowOverride None

    Order deny,allow

    Deny from 192.168.1.234                          //拒絕IP為192.168.1.234的主機訪問

</Directory>

[[email protected] /]# /etc/init.d/httpd restart

此時192.168.1.234客戶機將無法訪問www.benet.com/aws.html

 

使用者身份認證限制

首先使用htpasswd工具建立使用者認證資料檔案

[[email protected] /]# htpasswd -c /usr/local/httpd/conf/.awspwd xuhao

New password:

Re-type new password:

Adding password for user xuhao

[[email protected] /]# cat /usr/local/httpd/conf/.awspwd

xuhao:eE3EHFDzN4A5c

修改httpd.conf設定檔,添加使用者授權

[[email protected] /]# vim /usr/local/httpd/conf/httpd.conf

<Directory "/usr/local/awstats/wwwroot">

    Options None

    AllowOverride None

    Order allow,deny

    Allow from all

    AuthName "AWStats Directory"                        //定義受保護的領網域名稱稱

    AuthType Basic                                                //設定認證的類型

    AuthUserFile /usr/local/httpd/conf/.awspwd        //設定用於儲存使用者帳號、密碼檔案的路徑

    require valid-user                                             //合法使用者才能訪問

</Directory>

[[email protected] /]# /etc/init.d/httpd restart

 登入用戶端訪問測試

Apache與AWStats

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.