nginx+awstats安装

首先是下载awstats,这个现在是有中文网站了
解压后后放到/usr/local下
然后运行tools/awstats_configure.pl
按照提示进行配置,主要是网站的名字配置

然后是是nginx进行配置,如果是APACHE或者是IIS就不用这样麻烦了。
首先是配置nginx的日志格式

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" $http_x_forwarded_for';

这个要注意其中的标点和空格。

在nginx上跑awstats需要支持fastcgi和perl才可以
fastcgi这个安装方法很多,一般是编译php5的时候直接放进去就可以了。当然我们现在为了方便就直接使用nginx-fcgi脚本http://www.nginx.eu/nginx-fcgi.html

使用脚本前需要安装下列perl模块

perl -MCPAN -e 'install "FCGI“
perl -MCPAN -e 'install "Getopt::Long"'
perl -MCPAN -e 'install "IO::All"'
perl -MCPAN -e 'install "Socket"'

然后用nginx用户执行下列命令

/usr/bin/perl /usr/local/nginx/sbin/nginx-fcgi -S /tmp/fastcgi.sock -l /home/nginx/logs/nginx-cfgi.log -pid 100005

现在新的版本需要提供pid号才可以运行,这个可以自我进行设定。

配置fastcgi_params文件,perl_fastcgi_params同fastcgi_params

vi /usr/local/nginx/cconf/fastcgi_params
fastcgi_param QUERY_STRING       $query_string;
fastcgi_param REQUEST_METHOD     $request_method;
fastcgi_param CONTENT_TYPE       $content_type;
fastcgi_param CONTENT_LENGTH     $content_length;

fastcgi_param SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param REQUEST_URI        $request_uri;
fastcgi_param DOCUMENT_URI       $document_uri;
fastcgi_param DOCUMENT_ROOT      $document_root;
fastcgi_param SERVER_PROTOCOL    $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE    nginx/$nginx_version;
<br />
fastcgi_param REMOTE_ADDR        $remote_addr;
fastcgi_param REMOTE_PORT        $remote_port;
fastcgi_param SERVER_ADDR        $server_addr;
fastcgi_param SERVER_PORT        $server_port;
fastcgi_param SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS    200;

然后是awstats在nginix网站配置

   server {
                listen 8000;
                root /usr/local/awstats/wwwroot;
                index index.php;

                location ~* .php$ {
                        fastcgi_pass 127.0.0.1:9000;
                        access_log /home/nginx/logs/host.access.log main;
                        include fastcgi_params;
                }

                location ~* .pl$ {
                        fastcgi_pass unix:/tmp/fastcgi.sock;
                        access_log /home/nginx/logs/host.access.log main;
                        include perl_fastcgi_params;
                }

        }

最后如果执行以下命令没有错误就可以了。有错误就根据提示来进行修正。

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.zauc.com

最后浏览器的访问地址是
http://IP:8000/cgi-bin/awstats.pl?config=www.zauc.com

关于 Timo
XNIX SA & MYSQL DBA

3 Responses to nginx+awstats安装

  1. Pingback: 阿泰的菜园 » nginx+awstat安装配置

  2. 开心购物网说道:

    虚拟主机上怎么配,服务器是支持perl的,服务器perl版本为5.8.4.810。

    我改怎么配?

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: