Home Backend Development PHP Tutorial Apache服务器Log分析应用实例_PHP

Apache服务器Log分析应用实例_PHP

Jun 01, 2016 pm 12:40 PM
code analyze Example application server

Apache

Apache 服务器Log分析应用实例

rhinux 发表于: 2004-11-28 22:11



互联网的飞速发展,无论是传统企业的网站,还是互联网企业,为了了解自己的客户来源,点击率等资料,对网站日志的分析尤为重要,以下就本人所做的日志分析系统与大家分享,希望能对大家有所帮助。





欢迎大家复制,但请大家保留本文的完整,谢谢!!








一,所用软件及工具


1,Apache服务器 官方网址:http://www.apache.org


2,awstats 日志分析软件 官方网址:http://awstats.sourceforge.net/


3,cronolog 日志截取软件 官方网址:http://www.cronolog.org


二,环境构架


1,RedHat AS 3


2,Apache


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


make


make install


3, awstats


直接tar到 /usr/local/awstats


4,cronolog


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


make


make install


三, 配置


1, apache


a,让apache中的某个虚拟主机产生日志:





全局环境变量设置:


代码:
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






产生日志但不包括 图片。


虚拟主机日志设置


代码:



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


#用cronolog截取存放在/db/logs/下的按日期产生的apache日志文件






注:日志文件是针对每一个虚拟主机产生的所以可以配置一台服务器上多个虚拟主机的日志分析


b,别名设置


代码:



#


# 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 is to permit URL access to scripts/files in AWStats directory.


#





Options None


AllowOverride None


Order allow,deny


Allow from all









该配置在运行awstats/tools/awstats_configure.pl 后会自动产生所以不用手动添加。


c,awstats需要cgi的支持如果没有添加cgi可以现在添加


代码:



./apxs -c -i /usr/local/src/httpd-2.0.50/modules/generators/mod_cgi.c






再在httpd.conf 中添加


代码:



LoadModule cgi_module modules/mod_cgi.so






d为了保护日志统计信息需要对某些目录进行认证设置,需要认证模块的支持


代码:



./apxs -c -i /usr/local/src/httpd-2.0.50/..../mod_auth.c






再在httpd.conf 中添加


代码:



LoadModule auth_module modules/mod_auth.so






配置需要认证的目录:


代码:






AuthType Basic


AuthName "Restricted Files"


AuthUserFile /usr/local/apache2/passwd/passwords


Require user loguser









其中在 /usr/local/apache2/passwd/下产生passwords 的密码文件


运行如下代码产生用户名为loguser用户及其密码


代码:



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



注意:先要在 /usr/local/apache2/下建passwd目录


2,Awstats


运行 /usr/local/awstats/tools/awstats_configure.pl


主要设置的是需要输入做统计的主机名的配置文件名如:www.abc.net


接着修改 刚才配置是产生的awstats配置文件 默认位置在:


/etc/awstats/awstats.www.abc.net.con 主要做指定log位置


代码:



LogFile="/db/logs/www.%YYYY-4-%MM-2-%DD-2.log"






创建目录:mkdir /var/lib/awstats/


执行:


代码:



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






更新,update 后可以在浏览器中输入 http://www.abc.net/awstats/awstats.pl 进行访问了。








3,cronolog (基本不用什么修改)


4,crontab的修改


在 crontab中添加如下 命令保证15分钟更新一次,也可以根据你自己的需要修改更新的间隔


代码:



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






四,安全性考虑


1, 以上的设置由于要cgi支持,也增加了安全隐患可以用awstats 自带的awstats_buildstaticpages.pl来 生成静态页面 可以添加到crontab中


代码:



*/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






这样没15分钟在/db/htdocs/www/awstat/ 下生成各种静态页面





2,保护/db/htdocs/www/awstat/禁止未授权用户访问





在httpd.conf中添加


代码:






AuthType Basic


AuthName "Restricted Files"


AuthUserFile /usr/local/apache2/passwd/passwords


Require user loguser









如果www.abc.net 虚拟主机 主目录为/db/htdocs/www/ 则在浏览器中输入http://www.abc.net/awstat/awstats.www.abc.net.html 就可以通过认真访问静态页面


3,如果用静态页面就不要忘了注释掉


LoadModule cgi_module modules/mod_cgi.so








五,献给我最爱的飞飞。





六,由于本人是初学者,本文略显粗糙,如有任何指点和问题欢迎和我联系,大家相互交流提高 :hoash2003@hotmail.com



欢迎大家复制,但请大家保留本文的完整,谢谢!!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The role and practical application of arrow symbols in PHP The role and practical application of arrow symbols in PHP Mar 22, 2024 am 11:30 AM

The role and practical application of arrow symbols in PHP In PHP, the arrow symbol (->) is usually used to access the properties and methods of objects. Objects are one of the basic concepts of object-oriented programming (OOP) in PHP. In actual development, arrow symbols play an important role in operating objects. This article will introduce the role and practical application of arrow symbols, and provide specific code examples to help readers better understand. 1. The role of the arrow symbol to access the properties of an object. The arrow symbol can be used to access the properties of an object. When we instantiate a pair

How to Undo Delete from Home Screen in iPhone How to Undo Delete from Home Screen in iPhone Apr 17, 2024 pm 07:37 PM

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

How to configure Dnsmasq as a DHCP relay server How to configure Dnsmasq as a DHCP relay server Mar 21, 2024 am 08:50 AM

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

From beginner to proficient: Explore various application scenarios of Linux tee command From beginner to proficient: Explore various application scenarios of Linux tee command Mar 20, 2024 am 10:00 AM

The Linuxtee command is a very useful command line tool that can write output to a file or send output to another command without affecting existing output. In this article, we will explore in depth the various application scenarios of the Linuxtee command, from entry to proficiency. 1. Basic usage First, let’s take a look at the basic usage of the tee command. The syntax of tee command is as follows: tee[OPTION]...[FILE]...This command will read data from standard input and save the data to

How to install PHP FFmpeg extension on server? How to install PHP FFmpeg extension on server? Mar 28, 2024 pm 02:39 PM

How to install PHPFFmpeg extension on server? Installing the PHPFFmpeg extension on the server can help us process audio and video files in PHP projects and implement functions such as encoding, decoding, editing, and processing of audio and video files. This article will introduce how to install the PHPFFmpeg extension on the server, as well as specific code examples. First, we need to ensure that PHP and FFmpeg are installed on the server. If FFmpeg is not installed, you can follow the steps below to install FFmpe

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Jun 12, 2024 pm 08:38 PM

Since the launch of ChatGLM-6B on March 14, 2023, the GLM series models have received widespread attention and recognition. Especially after ChatGLM3-6B was open sourced, developers are full of expectations for the fourth-generation model launched by Zhipu AI. This expectation has finally been fully satisfied with the release of GLM-4-9B. The birth of GLM-4-9B In order to give small models (10B and below) more powerful capabilities, the GLM technical team launched this new fourth-generation GLM series open source model: GLM-4-9B after nearly half a year of exploration. This model greatly compresses the model size while ensuring accuracy, and has faster inference speed and higher efficiency. The GLM technical team’s exploration has not

Create and run Linux ".a" files Create and run Linux ".a" files Mar 20, 2024 pm 04:46 PM

Working with files in the Linux operating system requires the use of various commands and techniques that enable developers to efficiently create and execute files, code, programs, scripts, and other things. In the Linux environment, files with the extension ".a" have great importance as static libraries. These libraries play an important role in software development, allowing developers to efficiently manage and share common functionality across multiple programs. For effective software development in a Linux environment, it is crucial to understand how to create and run ".a" files. This article will introduce how to comprehensively install and configure the Linux ".a" file. Let's explore the definition, purpose, structure, and methods of creating and executing the Linux ".a" file. What is L

Detailed explanation of the advantages and utility of Golang server Detailed explanation of the advantages and utility of Golang server Mar 20, 2024 pm 01:51 PM

Golang is an open source programming language developed by Google. It is efficient, fast and powerful and is widely used in cloud computing, network programming, big data processing and other fields. As a strongly typed, static language, Golang has many advantages when building server-side applications. This article will analyze the advantages and utility of Golang server in detail, and illustrate its power through specific code examples. 1. The high-performance Golang compiler can compile the code into local code

See all articles