1 下载awstats
sudo apt-get install awstats 弄下来的版本在执行awstats_configure.pl时候找不到wwwroot目录结构,所以重新直接下载awstats了

bear@njava:~$tar xzvf awstats-6.95.tar.gz

2 执行配置脚本
先把 awstats目录复制到/usr/local/awstats,脚本是按照这个目录结构去执行的,如果不是在这/usr/local/awstats里,运行时回提示的

bear@njava:/usr/local/awstats/tools$ sudo ./ 
[sudo] password for bear: 

----- AWStats awstats_configure 1.0 (build 1.8) (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):
> none     #因为没法自动配置nginx,所以none

Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)

-----> 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: demo
Your web site, virtual server or profile name:
>   #配置名字

-----> 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):

-----> Create config file '/etc/awstats/'
 Config file /etc/awstats/ created.

-----> Add update process inside a scheduler
Sorry, 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/ -update
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/ now
Press ENTER to continue... 

A SIMPLE config file has been created: /etc/awstats/
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for '' with command:
> perl -update
You can also build static report pages for '' with command:
> perl -output=pagetype

Press ENTER to finish...


3 修改awstats配置文件

bear@njava:/usr/local/awstats/tools$ sudo vi /etc/awstats/awstats.conf
# LogFormat = 1
# LogFormat = "%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
# Example for IIS:
# LogFormat = 2
LogFormat =1  #继续使用apache的默认格式

AllowToUpdateStatsFromBrowser=1 #允许浏览器刷新,njava的流量小,这个可以有

Include "/etc/awstats/" #包含njava的配置

4 修改nginx的日志格式

bear@njava:/etc/awstats$sudo  vi /etc/nginx/nginx.conf
user www-data;
worker_processes  2;

error_log  /var/log/nginx/error.log;
pid        /var/run/;

events {
    worker_connections  1024;
    # multi_accept on;

http {
    include       /etc/nginx/mime.types;

    #main 把nginx的输出日志定义成了apache格式的日志
     log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for';

    access_log  /var/log/nginx/access.log main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

4 修改

bear@njava:/usr/local/awstats/tools$ sudo vi /etc/awstats/awstats.conf


5 配置nginx
先确保了nginx已经代理了nginx-fcgi,可以参看 xxx

bear@njava:/etc/awstats$ vi /etc/nginx/sites-enabled/  

server {
        listen   80;

        access_log   /var/log/nginx/awstats.log main;
        error_log    /var/log/nginx/awstats_error.log;

        root /usr/local/awstats/wwwroot;
        #auth_basic   "Restricted";
       #auth_basic_user_file  /etc/nginx/conf/awstats;

        location / {
             rewrite ^ /;

        location ~ .*(\.cgi|\.pl?)$ {
               gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped
               root /usr/local/awstats/wwwroot/cgi-bin;
                fastcgi_pass   unix:/tmp/nginx-fcgi.sock;
               fastcgi_param SCRIPT_FILENAME            $document_root$fastcgi_script_name;
               include        fastcgi_params;

         location /icon {
                alias /usr/local/awstats/wwwroot/icon;
  location /icon {
                alias /usr/local/awstats/wwwroot/icon;
  location /js {
                alias /usr/local/awstats/wwwroot/js;

  location /css {
                alias /usr/local/awstats/wwwroot/css;

  location /classes {
                alias /usr/local/awstats/wwwroot/classes;


bear@njava:/etc/nginx/conf$ sudo htpasswd -c awstats admin
New password: 
Re-type new password: 
Adding password for user admin

#auth_basic “Restricted”;
#auth_basic_user_file /etc/nginx/conf/awstats;

Tags: , ,

星期一, 三月 29th, 2010 服务器 没有评论