"Sharing" Nginx log analysis (top)

Source: Internet
Author: User


In many cases, we will be very concerned about the number of visits to the site, such as the site's daily PV is how much, the site of a feature on-line after the number of clicks, such as these things need to be from the Web container access log statistics, below we see how to count the site in Nginx access information


1. Set Nginx Access Logging format
By default, Nginx simply records the relevant get information, like the post page is not recorded, so the following need to modify nginx.conf, let its access log record post and other request information, in the Nginx.conf server segment to add the following information

Log_format access ' $remote _addr-$remote _user [$time _local] "$request" "$status $body _bytes_sent" $http _referer "" $h Ttp_user_agent "$http _x_forwarded_for";
Access_log/usr/local/nginx/logs/access.log access;


2, set the log to intercept regularly
Set Log periodic interception one is for easy access, the second is for I/O congestion (as far as I have maintained the server in a single server day access log size to 1.6G, if not regularly intercepted, due to the large file content, later on the file process query, mobile will seriously affect system performance). Nginx log format is not like Apache, resin so human, nginx access log can not be set in Nginx configuration file by date format storage, the current common setting method mainly rely on third-party tools or scripts to achieve, the following we have a simplest script to implement

#vi/etc/nginx_access_log.sh
#!/bin/bash
Mv/usr/local/nginx/logs/access.log/opt/nginx_access_ ' Date +%y%m%d '. Log
Killall-s USR1 Nginx

Script Description: This script mainly implements two functions, one is to move the Nginx access log by date to the destination, but after the move is finished, let Nginx regenerate the log file

#chmod +x/etc/nginx_access_log.sh

This script is executed periodically using the Cron service, which is set to execute every 23 o'clock in the evening 59, so that the Nginx access log records All-day access records exactly
#crontab-E
* * * */etc/nginx_access_log.sh


3. Log Query
Here is a simple statistic, statistics http://blog.luwenju.com page of the daily click on the amount of what
#grep-C ' http://blog.luwenju.com/'/opt/nginx_access_20110815.log
396

Summary: As the statistical method described in this article is only suitable for small access, relatively simple application of the site, such as complex applications, access to a large number of sites also need third-party tools to statistics, the most widely used is awstats, "Nginx log analysis (next)" Explains how to use Awstats to analyze Nginx logs

"Sharing" Nginx log analysis (top)

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.