Linux ---------- nginx log analysis

{nginx conventional log analysis as capable Maximilian Kalbfell} Reference Cipian

Nginx log format in which nginx.conf configuration, a common format configuration as follows:
log_format main 'REMOTE_ADDR $ - $ REMOTE_USER [$ time_local] "$ Request"'
'$ $ body_bytes_sent Status "$ HTTP_REFERER"'
' "$ HTTP_USER_AGENT" " HTTP_X_FORWARDED_FOR $ " ';
access_log logs / the access.log main;

Explain:
$ REMOTE_ADDR, $ HTTP_X_FORWARDED_FOR recording client IP address
$ REMOTE_USER recording client user name
$ request record URL and HTTP request
$ status record request status
$ body_bytes_sent to a number of bytes of the client, not including the size of the response header; this variable is compatible with the Apache module mod_log_config the parameters in "% B".
$ bytes_sent total number of bytes sent to the client.
$ connection_requests number of requests a connection obtained by the current.
$ http_referer recording which page to access links from over
$ http_user_agent record information about the client browser
lengths $ request_length requests (including request line, request headers and body of the request).
$ REQUEST_TIME request processing time, in seconds, milliseconds accuracy; starting from the first byte read client, until the last character sent to the client writes a log date.

Nginx is a very lightweight Web server, but does not automatically access log cutting nginx also considered a major shortcoming, it appends a script nginx automatic cutting logs, for your reference. (As used herein, the easiest way MV)

!/bin/bash

S_LOG=/usr/local/nginx/logs/access.log
D_LOG=/data/backup/date +%Y%m%d
echo -e "\033[32mPlease wait start cut log...\033[1m"
sleep 2
if [ ! -d $D_LOG ];then
mkdir -p $D_LOG
fi
mv $S_LOG $D_LOG
kill -USR1 cat /usr/local/nginx/logs/nginx.pid
echo "-------------------------------------------"
echo "The Nginx log Cutting Successfully!"
echo "You can access backup nginx log $D_LOG/access.log files."
vim /var/spool/cron/root (相当于crontab -e)
0 0 * * * /bin/sh /data/sh/auto_nginx_log.sh >>/tmp/nginx_cut.log 2>&1

Cipian learn from Ma Ying-jeou Maximilian Kalbfell

Guess you like

Origin www.cnblogs.com/wangchengshi/p/10966778.html
Recommended