自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Nginx配置文件實(shí)現(xiàn)AWStats靜態(tài)頁(yè)面

開發(fā) 前端
Nginx配置文件一直以來都需要我們不斷的學(xué)習(xí),那么我們?nèi)绾尾臢ginx配置文件中實(shí)現(xiàn)AWStats靜態(tài)頁(yè)面的效果呢?下面就會(huì)向大家詳細(xì)的介紹。

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

首先要參考之前的文章,建立好PERL+FCGI的運(yùn)行環(huán)境,這步準(zhǔn)備工作就夠費(fèi)勁的。

然后開始切入正題:

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)建一個(gè)存放awstats分析數(shù)據(jù)的目錄

mkdir /var/lib/awstats
chown www-data /var/lib/awstats //這是為了讓awstats頁(yè)面上能直接刷新***數(shù)據(jù)

3. 自動(dòng)配置awstats

cd /usr/local/awstats/tools
perl awstats_configure.pl

除了***步因?yàn)槭荖gin服務(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是因?yàn)槠涫褂霉艿垒敵?,?duì)系統(tǒng)資源消耗比較小,千萬不要忘了***的管道操作符!

假設(shè)原來/etc/Nginx/Nginx.conf中關(guān)于log部分是如此定義的:(要小心各個(gè)變量之間必須添加的空格,不能少,否則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”‘;

很容易知道,對(duì)應(yīng)awstats配置文件中,LogFormat應(yīng)該設(shè)置為
LogFormat= “%host %logname %time1 %methodurl %code %host_r %bytesd %gzipratio %refererquot %uaquot %otherquot”

***一個(gè)選%otherquot是應(yīng)為$http_x_forwarded_for在AWstats 6.95中還不認(rèn)識(shí)

3) 將AllowToUpdateStatsFromBrowser=1,便于瀏覽器中即時(shí)刷新數(shù)據(jù)

5. 更新Awstats的分析記錄,測(cè)試一下剛才的配置

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

  1. /var/log/nginx/*.log {  
  2. daily  
  3. missingok  
  4. rotate 7  
  5. compress  
  6. delaycompress  
  7. notifempty  
  8. create 640 www-data www-data  
  9. dateext  
  10. sharedscripts  
  11. prerotate  
  12. /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yoursite.com  
  13. sleep 59  
  14. endscript  
  15. postrotate  
  16. if [ -f /var/run/nginx.pid ]; then  
  17. kill -USR1 `cat /var/run/nginx.pid`  
  18. fi  
  19. endscript  

7. 接下來是最關(guān)鍵的NGINX配置文件

 

  1. #AWStatus Perl CGI server  
  2. server {  
  3. listen 80;  
  4. server_name awstats.yoursite.com;  
  5. access_log /var/log/nginx/awstats.log main;  
  6. error_log /var/log/nginx/awstats_error.log; #這可以為fail2ban留下記錄  
  7. root /usr/local/awstats/wwwroot;  
  8. auth_basic “Restricted”;  
  9. auth_basic_user_file /etc/nginx/awstatus.pass;  
  10. location = / {  
  11. rewrite ^ /awstats.pl?config=freshventure.info;  
  12. }  
  13. location ~ .*(\.cgi|\.pl?)$ {  
  14. gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped  
  15. root /usr/local/awstats/wwwroot/cgi-bin;  
  16. fastcgi_pass 127.0.0.1:8000;  
  17. fastcgi_index awstats.pl;  
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
  19. include fastcgi_params;  
  20. }  

 

好了,測(cè)試一下http://awstats.yoursite.com,和前文一樣,輸入密碼后,這次看到的應(yīng)該就awstats的界面了

8. 如果需要配置靜態(tài)頁(yè)面,則可以在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)頁(yè)就可以了。

【編輯推薦】

  1. nginx緩存的缺點(diǎn)和優(yōu)點(diǎn)專家評(píng)價(jià)
  2. nginx緩存如何避免傳統(tǒng)緩存的錯(cuò)誤
  3. nginx php如何解決502 Bad Gateway錯(cuò)誤
  4. nginx proxy反向代理的十五大技術(shù)特點(diǎn)
  5. nginx配置文件如何驗(yàn)證是否準(zhǔn)確
責(zé)任編輯:張浩 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-03-25 18:31:03

Nginx配置文件

2014-06-09 10:36:00

2010-02-22 15:59:48

2020-04-09 13:23:29

Nginx配置文件模板

2010-03-29 09:23:00

2010-03-25 17:46:27

nginx配置文件

2010-03-30 18:04:45

Nginx http服

2010-03-30 14:22:01

Nginx靜態(tài)文件

2013-10-31 11:08:15

2010-01-13 10:48:49

Centos設(shè)置

2010-02-06 14:00:05

Linux Nginx

2010-03-29 10:26:06

Nginx配置文件

2011-01-13 16:27:26

Linux配置文件

2011-01-19 14:00:21

2013-10-31 16:17:45

日志分析Awstats實(shí)戰(zhàn)Nginx

2022-04-28 09:46:20

Nginx文件Linux

2010-12-28 16:35:32

Outlook 配置文

2011-03-07 10:02:51

awstatstomcat

2010-12-27 14:59:31

Outlook 配置文

2010-08-05 14:36:07

NFS服務(wù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)