Nginx configuration file implements AWStats Static Page

Source: Internet
Author: User

The Nginx configuration file needs to be updated constantly in some cases. Although AWStats now supports output of analysis results in the form of static Web pages, the page layout is not convenient with dynamic web pages generated by Perl, in addition, the conversion tool compiled with Perl is a little slow. In the case of low traffic, it is more comfortable to run on Perl + Fast CGI.
 
First of all, you should refer to the previous article to establish the running environment of PERL + FCGI. This step of preparation is hard enough.
 
Then start to get started:
 
1. download the latest version of AWStats, which is basically a Perl package. Therefore, you do not need to use apt-get to decompress it to/usr/local/awstats.
 
Wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz
Tar-xzf awstats-6.95.tar.gz
Music awstats-6.95/usr/local/awstats
 
2. Create a directory for storing awstats analysis data
 
Mkdir/var/lib/awstats
Chown www-data/var/lib/awstats // This is to allow the awstats page to directly refresh the latest data
 
3. automatically configure awstats
 
Cd/usr/local/awstats/tools
Perl awstats_configure.pl
 
Except for the relationship between the Ngin server and the Ngin server, select none.
 
4. manually edit the Nginx configuration file
 
1) modify the LogFile path
 
LogFile = "/var/log/Nginx/access. log"
 
For logs in compressed format, use LogFile = "zcat/var/log/Nginx/%yyyy-24366mm-24366dd-24.gz | ". Zcat is used here because it uses pipeline output, which consumes less system resources. Do not forget the final pipeline operator!
 
Assume that the log section in/etc/Nginx. conf is defined as follows: (Be careful when spaces must be added between variables. Otherwise, awstats will not recognize them)
 
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 "';
 
It is easy to know that LogFormat should be set
LogFormat = "% host % logname % time1 % methodurl % code % host_r % bytesd % gzipratio % refererquot % uaquot % otherquot"
 
The last one selected % otherquot should be $ http_x_forwarded_for not recognized in AWstats 6.95
 
3) convert AllowToUpdateStatsFromBrowser = 1 to enable the browser to instantly refresh data.
 
5. Update the Awstats analysis record and test the configuration.
 
/Usr/local/awstats/wwwroot/cgi-bin/awstats. pl-update-config = yousite.com
 
If everything is normal, you should see results similar to the following:
 
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 successfully upted records,
Found 0 old records,
Found 1234 new qualified records.
 
6. Modify the Nginx configuration file under logrotate. d and update the awstats status before daily log splitting.
 
 
 
 
/Var/log/nginx/*. log {
 
 
Daily
 
 
Missingok
 
 
Rotate 7
 
 
Compress
 
 
Delaycompress
 
 
Notifempty
 
 
Create 640 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. Pi'
 
 
Fi
 
 
Endscript
 
 
}
 
 
 
 
7. Next is the most critical NGINX configuration file.
 
 
 
 
# 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; # This can leave a record for 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;
 
 
}
 
 
}
 
 
 
 
Okay, test the http://awstats.yoursite.com, just like the previous article, after entering the password, this time you should see the awstats Interface
 
8. If you need to configure static pages, you can replace 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.
 
To update access conditions more frequently, you can add this command to crontab, for example, crontab-e-uwww-data.
 
Then, adjust the nginx configuration file to display the static webpage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.