新聞中心
Nginx配置文件在有些時候需要我們不斷的更新,雖然AWStats現(xiàn)在已經(jīng)支持輸出靜態(tài)網(wǎng)頁形式的分析結(jié)果,但是頁面布局沒有用Perl生成的動態(tài)網(wǎng)頁方便,而且用自帶的用Perl編寫的轉(zhuǎn)換工具稍微有點慢,在流量不大的情況下,還是在Perl+Fast CGI上運行更舒服一些。

成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、賽罕網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站、商城開發(fā)、集團公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為賽罕等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
首先要參考之前的文章,建立好PERL+FCGI的運行環(huán)境,這步準(zhǔn)備工作就夠費勁的。
然后開始切入正題:
1. 下載***版的AWStats,基本就是Perl包,所以沒必要用apt-get,解壓縮到/usr/local/awstats下
wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz
tar -xzf awstats-6.95.tar.gz
mv awstats-6.95 /usr/local/awstats
2. 創(chuàng)建一個存放awstats分析數(shù)據(jù)的目錄
mkdir /var/lib/awstats
chown www-data /var/lib/awstats //這是為了讓awstats頁面上能直接刷新***數(shù)據(jù)
3. 自動配置awstats
cd /usr/local/awstats/tools
perl awstats_configure.pl
除了***步因為是Ngin服務(wù)器的關(guān)系,所以要選none,其他基本按照提示選默認(rèn)值
4. 手工編輯Nginx配置文件
1) 修改LogFile路徑
LogFile = “/var/log/Nginx/access.log”
如果是壓縮格式的日志,可以用LogFile = “zcat /var/log/Nginx/%YYYY-24%MM-24%DD-24.gz|"。這里用zcat是因為其使用管道輸出,對系統(tǒng)資源消耗比較小,千萬不要忘了***的管道操作符!
假設(shè)原來/etc/Nginx/Nginx.conf中關(guān)于log部分是如此定義的:(要小心各個變量之間必須添加的空格,不能少,否則awstats就不認(rèn)了)
log_format main ‘$remote_addr $remote_user [$time_local] “$request” $status ‘
‘$host $body_bytes_sent $gzip_ratio “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
很容易知道,對應(yīng)awstats配置文件中,LogFormat應(yīng)該設(shè)置為
LogFormat= “%host %logname %time1 %methodurl %code %host_r %bytesd %gzipratio %refererquot %uaquot %otherquot”
***一個選%otherquot是應(yīng)為$http_x_forwarded_for在AWstats 6.95中還不認(rèn)識
3) 將AllowToUpdateStatsFromBrowser=1,便于瀏覽器中即時刷新數(shù)據(jù)
5. 更新Awstats的分析記錄,測試一下剛才的配置
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yousite.com
如果一切正常,應(yīng)該看到類似以下的結(jié)果:
Create/Update database for config “/etc/awstats/awstats.yoursite.com.conf” by AWStats version 6.95 (build 1.943)
From data in log file “/var/log/Nginx/access.log”…
Phase 1 : First bypass old records, searching new record…
Searching new records from beginning of log file…
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)…
Jumped lines in file: 0
Parsed lines in file: 1234
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 1234 new qualified records.
6. 修改logrotate.d下的Nginx配置文件,在每天切割日志前,更新awstats狀態(tài)
- /var/log/ nginx /*.log {
- daily
- missingok
- rotate 7
- compress
- delaycompress
- notifempty
- create 640 www-data www-data
- dateext
- sharedscripts
- prerotate
- /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yoursite.com
- sleep 59
- endscript
- postrotate
- if [ -f /var/run/nginx.pid ]; then
- kill -USR1 `cat /var/run/nginx.pid`
- fi
- endscript
- }
7. 接下來是最關(guān)鍵的NGINX配置文件
- #AWStatus Perl CGI server
- server {
- listen 80;
- server_name awstats.yoursite.com;
- access_log /var/log/nginx/awstats.log main;
- error_log /var/log/nginx/awstats_error.log; #這可以為fail2ban留下記錄
- root /usr/local/awstats/wwwroot;
- auth_basic “Restricted”;
- auth_basic_user_file /etc/nginx/awstatus.pass;
- location = / {
- rewrite ^ /awstats.pl?config=freshventure.info;
- }
- 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 127.0.0.1:8000;
- fastcgi_index awstats.pl;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- }
好了,測試一下http://awstats.yoursite.com,和前文一樣,輸入密碼后,這次看到的應(yīng)該就awstats的界面了
8. 如果需要配置靜態(tài)頁面,則可以在logrotate中替換掉上面的awstats.pl, 換成
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=yoursite.com -lang=cn -dir=/usr/local/awstats/wwwroot -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl。
如果需要更頻繁的更新訪問情況,則可以把這句命令加入到crontab中,例如crontab -e -uwww-data。
然后nginx配置文件相應(yīng)調(diào)整為顯示靜態(tài)網(wǎng)頁就可以了。
本文題目:Nginx配置文件實現(xiàn)AWStats靜態(tài)頁面
網(wǎng)站網(wǎng)址:http://fisionsoft.com.cn/article/dphsggs.html


咨詢
建站咨詢
