您现在的位置:爱折腾>> Linux>>正文内容

ubuntu上安装awstats监控nginx网站流量

首先 确认nginx的log格式为以下格式: (/usr/local/nginx/conf/vhost/www.yy425.com.conf)
为:
log_format www_log '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

新装LNMP可以直接修改vhost.sh文件:
alf="log_format $al_name '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '
'\$status \$body_bytes_sent \"\$http_referer\" '
'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';"
al="access_log /home/wwwlogs/$al_name.log $al_name;"

(修改内容为http_x_forwarded_for的双引号)

如果已经有log要在修改好log格式后删除原有log 然后重启nginx
=================================
安装awstats
下载awstats7.1.1
wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/7.1.1/awstats-7.1.1.tar.gz

tar xzf awstats-7.1.1.tar.gz
mv awstats-7.1.1 /usr/local/awstats
cd /usr/local/awstats/tools
mkdir /etc/awstats /var/lib/awstats

===================================]
配置 多网站使用的话重复这一步骤
perl awstats_confi*re.pl

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 *ysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
>www.linuxyan.com

—–> 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, confi*re.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.linuxyan.com
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.linuxyan.com
You can also build static report pages for ‘www.linuxyan.com’ with command:
> perl awstats.pl -output=pagetype -config=www.linuxyan.com
Press ENTER to finish…回车

=======================================
编辑配置文件 目录/etc/awstats/
修改LogFile=”/home/wwwlogs/www.yy425.com.log”

执行 可以将这句写入crontab
注意中间有配置的域名
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.centos.bz -update -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/home/wwwroot/awstats
访问:
http://ip或域名/awstats/awstats.www.yy425.com.html

我的vps由于事先已经安装了中文 如果显示英文的话 可以执行
apt-get install lan*age-selector lan*age-env lan*age-pack-zh-hans
安装中文库


相关文章