Apache Server Log Analysis application example

Source: Internet
Author: User
Tags config copy log modify net require apache log access
apache| Server | Application Example Apache Server log Analysis application example

Rhinux published in: 2004-11-28 22:11



The rapid development of the Internet, whether it is a traditional enterprise website, or Internet enterprises, in order to understand their own customer source, click rate and other information, the site log analysis is particularly important, the following I do the log analysis system to share with you, hope to be helpful to everyone.





Welcome everyone to copy, but please keep the integrity of this article, thank you!!








First, the software and tools used


1,apache Server Official website: http://www.apache.org


2,awstats Log Analysis Software official website: http://awstats.sourceforge.net/


3,cronolog log Interception Software official website: http://www.cronolog.org


Second, environmental framework


1,redhat as 3


2,apache


./configure–prefix=/usr/local/apache2/--enable-so


Make


Make install


3, Awstats


Direct tar to/usr/local/awstats


4,cronolog


./configure–prefix=/usr/local/cronolog


Make


Make install


Third, configure


1, Apache


A, let a virtual host in Apache generate the log:





Global environment variable settings:


Code:
Logformat "%h%l%u%t \%r\"%>s%b \ "%{referer}i\" \ "%{user-agent}i\" "combined


Setenvif Request_uri \.gif$ Gif-image


Setenvif request_uri \. gif$ Gif-image


Setenvif Request_uri \.jpg$ Gif-image


Setenvif request_uri \. jpg$ Gif-image


Setenvif Request_uri \.png$ Gif-image


Setenvif Request_uri \.swf$ Gif-image


Setenvif request_uri \. swf$ Gif-image


Setenvif Request_uri \.css$ Gif-image


Setenvif request_uri \. css$ Gif-image


Setenvif Request_uri \.js$ Gif-image


Setenvif request_uri \. js$ Gif-image


Setenvif Request_uri \.ico$ Gif-image






Generates a log but does not include a picture.


Virtual Host Log Settings


Code:
<virtualhost 12.34.56.78:80>


ServerAdmin webmaster@abc.net


Documentroot/db/htdocs/www


ServerName www.abc.net


Customlog "|/usr/local/cronolog/sbin/cronolog/db/logs/www.%y-%m-%d.log" combined Env=!gif-image


Apache log files by date #用cronolog截取存放在/db/logs/


</VirtualHost>



Note: Log files are generated for each virtual host so you can configure log analysis of multiple virtual hosts on a single server


B, alias settings


Code:



#


# directives to allow use of AWStats as a CGI


#


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


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


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


scriptalias/awstats/"/usr/local/awstats/wwwroot/cgi-bin/"





#


# This are to permit URLs access to scripts/files in AWStats directory.


#


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


Options None


AllowOverride None


Order Allow,deny


Allow from all


</Directory>






This configuration is automatically generated after running awstats/tools/awstats_configure.pl, so you do not need to add them manually.


C,awstats need CGI support if no CGI is added you can now add


Code:



./apxs-c-I/USR/LOCAL/SRC/HTTPD-2.0.50/MODULES/GENERATORS/MOD_CGI.C






and add it to the httpd.conf.


Code:



LoadModule Cgi_module modules/mod_cgi.so






D in order to protect the log statistics need to some directory authentication settings, the need for authentication module support


Code:



./apxs-c-I/USR/LOCAL/SRC/HTTPD-2.0.50/..../MOD_AUTH.C






and add it to the httpd.conf.


Code:



LoadModule Auth_module modules/mod_auth.so






To configure the directory to be authenticated:


Code:



<directory "/db/htdocs/www/awstat/" >


AuthType Basic


AuthName "Restricted Files"


Authuserfile/usr/local/apache2/passwd/passwords


Require User LogUser


</Directory>






Where the passwords password file is generated under/usr/local/apache2/passwd/


Run the following code to produce a user named LogUser user and their password


Code:



/usr/local/apache2/bin/htpasswd-c/usr/local/apache2/passwd/passwords LogUser



Note: First, the passwd directory should be built under/usr/local/apache2/


2,awstats


Run/usr/local/awstats/tools/awstats_configure.pl


The main setting is the configuration name of the host name that needs to be entered for statistics, such as: www.abc.net


Then modify the default location of the Awstats configuration file that was created just now:


/etc/awstats/awstats.www.abc.net.con mainly do specify log location


Code:



Logfile= "/db/logs/www.%yyyy-4-%mm-2-%dd-2.log"






Create a table of contents: mkdir/var/lib/awstats/


Perform:


Code:



/usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update-config=www.abc.net






Update, you can enter http://www.abc.net/awstats/awstats.pl in the browser to access it after update.








3,cronolog (basically without any modification)


Modification of 4,crontab


Add the following command to the crontab to ensure a 15-minute update, or modify the update interval according to your own needs


Code:



*/15 * * * */usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update-config=www.abc.net






Four, security considerations


1, the above settings due to CGI support, but also increased security vulnerabilities can be awstats with the awstats_buildstaticpages.pl to generate static pages can be added to the crontab


Code:



*/15 * * * */usr/local/awstats/tools/awstats_buildstaticpages.pl-update-config=www.abc.net-lang=cn-dir=/db/htdocs/ www/awstat/-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl






That's not 15 minutes to generate a variety of static pages under/db/htdocs/www/awstat/.





2, protect/db/htdocs/www/awstat/prohibit unauthorized user access





Add in httpd.conf


Code:



<directory "/db/htdocs/www/awstat/" >


AuthType Basic


AuthName "Restricted Files"


Authuserfile/usr/local/apache2/passwd/passwords


Require User LogUser


</Directory>






If the Www.abc.net virtual host directory is/db/htdocs/www/, enter http://www.abc.net/awstat/awstats.www.abc.net.html in the browser to access the static page carefully


3, if you use a static page, don't forget to comment out


LoadModule Cgi_module modules/mod_cgi.so








Five, to my favorite flying fly.





Six, because I am a beginner, this article slightly rough, if there is any guidance and questions welcome and I contact, we exchange each other to improve: hoash2003@hotmail.com



Welcome everyone to copy, but please keep the integrity of this article, thank you!!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.