Use awstats to analyze Nginx access logs

Source: Internet
Author: User
Article Title: Use awstats to analyze Nginx access logs. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Preface

In my previous article "linux.chinaitlab.com/server/768231.html" target = _ blank>Use Nginx to speed up Website accessThis section describes the Nginx HTTP server and how to use it to accelerate Website access. In actual website operations, we often need to know the Website access information, for example, how many IP addresses are accessed each day, how many PVS are there, which URL has the largest access volume, which browser is the most used by users, how do you know the website and how many user access errors occur? wait, by mastering this information, we can improve the user experience and the quality of the website. Generally, we can use some free access statistics websites, such as Google Analytics, or such information. However, the disadvantage is that such websites can only analyze pages, excluding static files. In addition, many webmasters may not want to use such tools to expose their own data, these factors make the webmaster want to analyze access logs by themselves. Awstats can meet all these requirements.

Awstats is a fast-growing Perl-based WEB log analysis tool on SourceForge. A full log analysis allows Awstats to show you the following information:

● Number of visits, unique visitor count,
● Access time and last access,
● User authentication and recently authenticated access,
● Weekly peak hours (pages, click rate, kilobytes per hour and week ),
● Domain name/country host visitor (page number, click rate, byte, 269 domain name/country detection, geoip Detection ),
● Host list, recently accessed and unresolved IP address list
● Most of the accessed pages,
● File type,
● Website compression statistical table (mod_gzip or mod_deflate ),
● Operating system used (number of pages per operating system, click rate, byte, 35 OS detected ),
● The browser used,
● Robot access (detect 319 robots ),
● Worm attacks (five worm families ),
● The search engine uses keyword search to find your address,
● HTTP protocol error (a page not found recently ),
● Other URL-based Personalized reports and link parameters that involve the purpose of integrated marketing.
● Your website has been added to "favorite bookmarks". Times.
● Screen size (HTML tags need to be added on the index page ).
● Browser support ratio: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, and PDF reader.
● Load balancing server ratio cluster report.
The running of Awstats requires support from the PERL environment. From the awstats documentation, it provides excellent support for Apache HTTP Server. When we replace the Web Server with Nginx, it is troublesome to run awstats. Nginx has poor support for Perl, and is not even recommended by the official team. In addition, you need to modify the log format before running Nginx.

This article describes how to enable awstats to generate a static page for the log statistics result, and then use Nginx output to calculate Nginx access logs. It also describes how to enable Nginx to automatically cut log files.

Configure Nginx to automatically cut logs

Different from Apache HTTP Server (Apache), Apache can redirect log output through pipelines to perform Automatic Log cutting. In today's version, Nginx has not been able to create logs in batches by date using parameters such as % YY, but by sending a specific signal to the nginx process, nginx can be used to generate a log file again. We can regularly execute a Shell script to switch logs, rename or transfer logs. The specific script is as follows:

# Mv/opt/nginx/logs/access. log/opt/nginx/logs/access _ 'date + % Y % m % D'. log
# Killall? S USR1 nginx # Use the USR1 parameter to notify the Nginx process to switch log files

Save the preceding script content as logcron. sh and save it to a custom directory, for example,/opt/nginx/sbin/logcron. sh.

Use Crontab to automatically execute the script program at every night to create logs by day.

[1] [2] [3] [4] Next page

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.