Konfigurasi Awstats, Perl, FCGI yang Benar di Nginx CentOS
Assalamu’alaikum Wr. Wb
Hehe, seperti biasa mau curhat dulu kenapa ak nulis tulisan ini. Awalnya sih pengen ngeliat summary dari log nginx website. Dicari-cari eh ketemu deh awstats. Log nya nginx jadi gampang banget diliat loh teman-teman, jadi grafik2 gitu jg.. Di akhir tulisan saya kasih screenshoot nya yah. Sekarang saya tulis dlu nih langkah2 install ma konfigurasi awstats nya di nginx pada OS linux CentOS. Check it out:
- Install dulu kebutuhan dari perl-fcgi yaitu paket fcgi-perl.x86_64 dan perl-FCGI-ProcManager
#yum install perl-FCGI-ProcManager.noarch #yum install fcgi-perl.x86_64
- Buat file dengan nama /usr/local/bin/cgiwrap-fcgi.pl . Kemudian isi file tersebut dengan ini:
- Kemudian ubah permisi file nya agar biar bisa dieksekusi
#chmod +x /usr/local/bin/cgiwrap-fcgi.pl
- Jalankan secara background, agar mudah untuk mengerjakan yang lain
perl /usr/local/bin/cgiwrap-fcgi-pl &
- Setelah berjalan kita tinggal mengkonfigurasi lainnya, yaitu konfigurasi log nginx nya. Melakukan cutting terhadap log di nginx untuk dapat diproses ke dalam awstats adalah sangat penting. Caranya yaitu dengan membuat script logcut.sh dengan isi command di bawah:
# mv /var/log/nginx/access.log /var/log/nginx/access_`date +%Y%m%d`.log # killall –s USR1 nginx
Pada baris pertama akan mengganti file access.log menjadi access_(tahun skrng)(bulan skrng)(tgl skrng).log. Kemudian baris kedua adalah membuka kembali log untuk dibuat log sesuai dengan konfigurasi nginx.
- Masukkan file tersebut ke cron agak bisa dijalankan secara otomatis 1x tiap hari nya. Jalankan:
#crontab -e
Tambahkan command di bawah di file crontab:
#55 23 * * * /root/./logcut.sh
Maksud nya cron di atas yaitu menjalankan script di atas tiap pukul 23.55
- Download awstats terlebih dahulu disini
Pilih yang stabil saja kalau saya, hehe - Ekstrak file tersebut di /usr/local/.
#tar -zxvf awstats-7.0.tar.gz
- Kemudian lakukan konfigurasi terhadap awstats dengan menjalankan awstats_configure.pl
#perl awstats_configure.pl
-----> 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 Enter 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 Enter -----> Define config file name to create What is the name of your web site or profile analysis ? Example: www.mysite.com Example: demo Your web site, virtual server or profile name: #> www.muazfa.info www.muazfa.info Enter -----> 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): #> Enter directly using the default, then there will be the following tips ----> Add update process inside a scheduler Sorry, configure.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=wwww.muazfa.info Or if you have several config files and prefer having only one command: /usr/local/awstats/tools/awstats_updateall.pl nowA SIMPLE config file has been created: /etc/awstats/awstats.www.muazfa.info.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'www.muazfa.info' with command: > perl awstats.pl -update -config=www.muazfa.info You can also build static report pages for 'www.muazfa.info' with command: > perl awstats.pl -output=pagetype -config=www.muazfa.info Press ENTER to finish... - Ada beberapa konfigurasi dari awstats yang harus di ubah terlebih dahulu. Nih konfigurasi2nya yang sudah dirubah:
LogFile="/var/log/nginx/tolongdong.com_access_%YYYY-0%MM-0%DD-0.log" LogFormat= "%host - %host_r %time1 %methodurl %code %bytesd %refererquot %uaquot %otherquot" DirCgi="/cgi-bin" DirIcons="/icon" AllowToUpdateStatsFromBrowser=1
- LogFile -> untuk menempatkan log file sesuai dengan file logcut.sh yg telah kita buat
- LogFormat -> format log disesuaikan dengan format log yang ada di nginx. Di konfigurasi nginx harus disesuaikan kembali. yaitu sebagai berikut:
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;
- DicCgi disesuaikan dengan letak folder cgi-bin di folder root nginx
- DirIcons disesuaikan juga dengan letak konfigurasi icon
- AllowToUpdateStatsFromBrowser=1 -> digunakan agar konfigurasi dapat diupdate langsung lewat browser. Nah apabila kita mengaktifkan ini, maka kita harus memberikan permisi untuk write di folder /var/lib/awstats. Caranya:
chmod -R 666 /var/lib/awstats
- Nah setelah itu tuh konfigurasi kan sistem lagi sesuai dengan konfigurasi kita. Yaitu konfigurasi cgi-bin, icon sehingga dapat update lewat browser. Langsung aj yah. hehe
- Konfigurasi cgi-bin agar bisa diakses untuk masalah agar bisa di akses langsung lewat browser. Nih langkah2nya:
- Copy dulu folder awstats ke folder root nginx
#cp /usr/local/awstats /home/muazfa/public_html/
- Ganti permisi file awstats.pl agar bisa dieksekusi
#chmod +x /home/muazfa/public_html/awstats/wwwroot/cgi-bin/awstats.pl
- Edit konfigurasi nginx di /etc/nginx/nginx.conf menjadi:
location ~ ^/cgi-bin/ { set $php_root /home/muazfa/public_html/awstats/wwwroot; gzip off; include fastcgi_params; fastcgi_pass 127.0.0.1:8999; fastcgi_index awstats.pl; fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $document_root; } - Restart nginx nya terlebih dahulu. Kemudian akan bisa diakses dengan menjalankan http://muazfa.info/cgi-bin/?config=www.muazfa.info
- Akan sangat riskan apabila tidak diberi password. Lakukan tahap berikut agar bisa diberi password:
- Pindah direktori ke /home/muazfa/public_html/awstats/wwwroot/cgi-bin/. Kemudian jalankan
htpasswd -c .htpasswd admin
- tambahkan konfigurasi nginx menjadi seperti ini:
location ~ ^/cgi-bin/ { auth_basic "admin"; auth_basic_user_file .htpasswd; set $php_root /home/muazfa/public_html/awstats/wwwroot; gzip off; include fastcgi_params; fastcgi_pass 127.0.0.1:8999; fastcgi_index awstats.pl; fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $document_root; }
- Pindah direktori ke /home/muazfa/public_html/awstats/wwwroot/cgi-bin/. Kemudian jalankan
- Restart nginx, maka untuk mengakses awstat akan meminta username dan password
- Copy dulu folder awstats ke folder root nginx
- Konfigurasi icon agar dapat diakses dengan benar yaitu dengan cara berikut:
- Edit konfigurasi nginx lagi dengan menambahkan ini:
location ^~ /icon { alias /home/muazfa/public_html/awstats/wwwroot/icon/; } - Restart nginx, maka icon dapat diakses oleh awstats.pl di browser dengan baik
- Edit konfigurasi nginx lagi dengan menambahkan ini:
- Kemudian kita akan masuk ke tahap2 akhir, menambahkan update config awstats.pl otomatis beberapa saat setelah dijalankan skrip logcut.sh. Nih langsung aj tambahkan ke crontab:
#crontab -e
Tambahkan skrip dibawah
00 1 * * * perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.muazfa.info
- Nih kesimpulan alur awstats nya:
- Hehe, mungkin itu aj nih cukup..

Mungkin dapat membantu teman2 ^^. Kasih aj saran kalau ada salah2 yah, hehe
sumber:
http://www.goitworld.com/analysis-access-logs-of-nginx-by-awstats/
http://blog.cykerway.com/post/264
http://www.ibm.com/developerworks/cn/linux/l-cn-awstats-nginx/index.html
No related posts.
Tags: Awstats, Benar, CentOS, FCGI, konfigurasi, nginx, Perl
