nginx service log information

First, the error log

vim nginx.conf
error_log  /tmp/error.log error;

 语法:
 Syntax:    error_log file [level];
 Default:   
error_log logs/error.log error;
Context:    main, http, mail, stream, server, location
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 补充说明:
 错误日志的,默认情况下不指定也没有关系,因为nginx很少有错误日志记录的。
 但有时出现问题时,是有必要记录一下错误日志的,方便我们排查问题。
error_log 级别分为 debug, info, notice, warn, error, crit  默认为crit 
该级别在日志名后边定义格式如下:
error_log  /your/path/error.log crit;  
crit 记录的日志最少,而debug记录的日志最多。
如果nginx遇到一些问题,比如502比较频繁出现,但是看默认的error_log并没有看到有意义的信息,
那么就可以调一下错误日志的级别,当你调成error级别时,错误日志记录的内容会更加丰富

Second, the access log (focus)

    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  logs/access.log  main;                    --- 调用定义格式信息,生成访问日志

 变量详解:(官方链接:http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log)

$remote_addr       10.0.0.1           --- 访问客户端的源地址信息
$remote_user          -               --- 访问客户端认证用户信息   ???
[$time_local]                         --- 显示访问时间
$request        GET / HTTP/1.1        --- 请求行信息
$status              304              --- 状态码信息(304状态码利用缓存显示页面信息)
$body_bytes_sent                      --- 服务端响应客户端的数据大小信息
$http_referer                         --- 记录链接到网站的域名信息  ???
$ http_user_agent                      --- 用户访问网站客户端软件标识信息
                                         用户利用客户端浏览器测试访问时,win10默认浏览器会有异常问
$http_x_forwarded_for                 --- ???  反向代理

Third, the logs to be cut

  1. Shell script implemented using log cutting
    [the root @ web01 scripts] Vim cut_log.sh #
    # / bin / the bash!
    Data_info = $ (DATE% +% F-H:% M)

    mv /application/nginx/logs/www_access.log /application/nginx/logs/access.log.$data_info
    /application/nginx/sbin/nginx -s reload

  2. Timing the cron job log Nginx Cut
    . ./6... / Bin / SH & /server/scripts/cut_log.sh> / dev / null

Guess you like

Origin blog.51cto.com/tangyong/2431519