| 
       
	不多说话,看操作 
	首先配置nginx的日志格式,,因为nginx默认的日志格式awstats是不能分析的,必要要把nginx的格式改为和apache的日志格式一样才行, 
	nginx日志格式定义如下: 
log_format  www_log  '$remote_addr - $remote_user [$time_local] "$request" '
                                      '$status $body_bytes_sent "$http_referer" '
                                      '"$http_user_agent" "$http_x_forwarded_for"';
	注意了,看清楚了,,,一个字符都不能少,如果你的awstats能正常显示页面,但是所有的数据都是0的话,就是你的日志格式没有定义好。 
	然后在server段里面记录日志的时候启用www_log格式。如下: 
access_log  /home/nginx_log/www.it.net.cn.access.log  www_log; 
	nginx的日志格式设置好之后,就开始安装配置awstats了 
	awstats下载安装 
wget http://prdownloads.sourceforge.net/awstats/awstats-7.0.tar.gz
tar xzf awstats-7.0.tar.gz
mv awstats-7.0 /usr/local/awstats
cd /usr/local/awstats/tools
mkdir /etc/awstats /var/lib/awstats 
	awstats配置 
	perl awstats_configure.pl 
	—–> 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): 
	>none 
	—–> 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.it.net.cn 
	—–> Define config file path 
	In which directory do you plan to store your config file(s) ? 
	Default: /etc/awstats 
	Directory path to store config file(s) (Enter for default): 
	>回车 
	Sorry, configure.pl does not support automatic add to cron yet. 
	You can do it manually by adding the following command to your cron: 
	/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.it.net.cn 
	Or if you have several config files and prefer having only one command: 
	/usr/local/awstats/tools/awstats_updateall.pl now 
	Press ENTER to continue…回车 
	> perl awstats.pl -update -config=www.it.net.cn 
	You can also build static report pages for ‘www.it.net.cn’ with command: 
	> perl awstats.pl -output=pagetype -config=www.it.net.cn 
	Press ENTER to finish…回车 
	然后需要编辑配置文件awstats.www.it.net.cn.conf。 
	vi /etc/awstats/awstats.www.it.net.cn.conf 
	只需要定义日志的路径,如: 
	LogFile=”/home/nginx_log/www.it.net.cn.access.log” 
	复制css和icon目录到网站根目录。 
	cp -R /usr/local/awstats/wwwroot/css /var/www/html 
	cp -R /usr/local/awstats/wwwroot/icon /var/www/html 
	手动执行命令更新日志统计数据库及生成静态文件到目录/var/www/html/awstats: 
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.centos.bz -update -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/var/www/html/awstats 
	之后你就可以使用http://ip或域名/awstats/awstats.www.it.net.cn.html访问日志统计页面。 
	这个时候还是英文的,,可以修改配置文件来生成中文的 
vi /etc/awstats/awstats.www.it.net.cn.conf
Lang="cn"
LoadPlugin="decodeutfkeys" 
	修改之后重新生成静态文件,如果是乱码的话,把浏览器的编码改为GB2312就可以正常显示中文了。 
	添加脚本awstats_buildstaticpages.pl到cron定时生成日志统计页面。 如下是每5分钟统计一次 
crontab -e
*/5 * * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.centos.bz -update -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/var/www/html/awstats 
	awstats_buildstaticpages.pl脚本使用说明: 
	语法:awstats_buildstaticpages.pl (awstats_options) [awstatsbuildstaticpages_options] 
	awstats_options可选参数为: 
	-config=configvalue:定义配置文件,如www.centos.bz,就会搜索/etc/awstats/awstats.www.centos.bz.conf文件。 
	-update :该选项定义生成静态页面之前先更新数据库。 
	-lang :统计页面的语言,如-lang=cn,语言为中文。 
	awstatsbuildstaticpages_options可选参数为: 
	-awstatsprog=pathtoawstatspl :定义awstats.pl路径。 
	-dir :定义输出静态页面的目录。 
      (责任编辑:IT) |