nginx-日志

Posted hulue

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx-日志相关的知识,希望对你有一定的参考价值。

nginx日志

错误日志增加一行 error_log logs/error.log;

Nginx日志格式默认参数:

    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;

参数变量说明:

技术分享图片

 

 nginx.conf配置文件

worker_processes  1;

error_log  logs/error.log;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    error_log  logs/error.log;
    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;

    sendfile        on;
    keepalive_timeout  65;
include zj/hello.conf;
include zj/world.conf;

 虚拟主机配置文件

添加一行(每个虚拟主机都要加一行):access_log logs/access_www.log main;

后面加上 buffer 和 f;ush选项,提升网站访问性能。

    server {
        listen       9999;
        server_name  www.world.com;
        location / {
            root   html/world;
            index  index.html index.htm;
        }
        access_log logs/access_www.log main gzip buffer=32k flush=5s;    
    }

 

日志轮询切割-切割脚本

#!/bin/sh
Dateformat=`date +%Y%m%d`
Basedir="/appliction/nginx"
Nginxlogdir="$Basedir/logs"
Logname="access_www"
[ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1
[ -f ${Logname}.log  ]|| exit 1
/bin/mv ${Logname}.log  ${Dateformat}_${Logname}.log
$Basedir/sbin/nginx -s reload

 定时任务,每天00点执行脚本

脚本名:nginx_log.sh  存放目录:/mnt/script/nginx_log.sh

cat >>/var/spool/cron/root << EOF

00 00 * * * /bin/sh /mnt/script/nginx_log.sh >/dev/null 2>&1

EOF

 

以上是关于nginx-日志的主要内容,如果未能解决你的问题,请参考以下文章

argparse 代码片段只打印部分日志

常用python日期日志获取内容循环的代码片段

Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error code(代码片段

我的Android进阶之旅NDK开发之在C++代码中使用Android Log打印日志,打印出C++的函数耗时以及代码片段耗时详情

使用命令如何动态查看nginx.log日志文件的内容?

webstorm代码片段的创建