nginx日志格式配置
我一向对日志这个东西有些许恐惧,因为在分析日志是需要记住不同服务器日志的格式,就拿提取ip这一项来说,有的服务器日志是在第一列,有的是第二列或则第三列等等。知道今天我才发现,日志格式是可以自定义配置的。。。。 
现在我们来看一下nginx的日志格式如何自定义配置 
log_format指令用来设置日志格式,其语法如下: 
log_format name format [format …]
nginx默认日志格式具体参数如下:
log_format combined '$remote_addr - $remote_user [$time_local]'
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
看一下一条nginx日志
192.168.3.113 - - [23/Jul/2017:01:17:43 -0700] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
可以看到分别对应的是ip 远程用户名 时间 请求 请求状态 以及用户客户端信息等等
那么日志配置是在哪里进行配置的呢
[root@localhost nginx]# !446
cat conf/nginx.conf|grep -v "#"|grep -v "^$"
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format mylog '$remote_addr [$time_local]' '"$http_user_agent"';          #在这里进行配置,命名为mylog,也可以把这条语句放在server里面
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.bp1.com;
        location / {
            root   html;
            index  index.html index.htm index.php;
        }
        error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    server{
        listen 192.168.3.123:80;
        server_name www.bp3.com;
        access_log logs/bp2.access.log mylog;     #使用刚配置的日志文件格式mylog
        location /
        {
            index index.html index.php;
            root html/bp2;
        }
        location ~ \.php$ {
            root           html/bp2;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    server{
        listen 192.168.3.125:80;
        server_name www.bp2.com;
        location /{
            root html/bp3;
            index index.html index.php;
        }
        location ~ \.php$ {
            root           html/bp3;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}
[root@localhost nginx]#
效果
192.168.3.113 [23/Jul/2017:01:37:51 -0700]"Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
nginx日志格式配置的更多相关文章
- Nginx 日志格式配置介绍
		
Nginx日志格式配置介绍 by:授客 QQ:1033553122 测试环境 CentOS 6.5-x86_64 nginx-1.10.0 配置例子 log_format main '$ ...
 - 运维技巧-Nginx日志格式
		
1.说一说 当你安装完nginx,输出的格式是比较乱的,这样我们就需要自己去定义一下,自己看着舒服的格式. 2.Nginx日志字段 $remote_addr 记录客户端IP,但她的值不是客户端提供的, ...
 - Nginx日志格式以及相关配置
		
一.Nginx日志格式以及参数说明log_format main '$remote_addr - $remote_user [$time_local] "$request" ' ...
 - Nginx日志文件配置与切割
		
Nginx日志的指令主要有两条: log_format,设置日志的格式 access_log,指定日志文件的存放路径.格式和缓存大小 两条指令在Nginx配置文件中的位置可以在http{……..}之间 ...
 - ELK 之三:Kibana 使用与Tomcat、Nginx 日志格式处理
		
一:kibana安装: kibana主要是搜索elasticsearch的数据,并进行数据可视化的展现,新版使用nodejs. 1.下载地址: https://www.elastic.co/downl ...
 - nginx日志 logrotate配置
		
nginx 日志 logrotate配置如下: /var/log/nginx/*.log { daily missingok rotate 20 compress delaycompress noti ...
 - Nginx - 日志格式及输出
		
1. 前言 在 Nginx 服务器中,如果想对日志输出进行控制还是很容易的.Nginx 服务器提供了一个 HttpLogModule 模块,可以通过它来设置日志的输出格式. 2. HttpLogMod ...
 - nginx日志输出配置json格式
		
修改nginx配置文件 http { include mime.types; default_type application/octet-stream; charset utf-8; # 原有日志格 ...
 - nginx日志格式字段
		
Nginx日志主要分为两种:访问日志和错误日志.日志开关在Nginx配置文件(/etc/nginx/nginx.conf)中设置,两种日志都可以选择性关闭,默认都是打开的. 访问日志 访问日志主要记录 ...
 
随机推荐
- jdk8-全新时间和日期api
			
1.jdk8日期和时间api是线程安全的 1.java.time 处理日期时间 2.java.time.temporal: 时间校正器.获取每个月第一天,周几等等 3.java.time.forma ...
 - 深入理解java虚拟机---内存分配策略(十三)
			
转载请注明原文地址:https://blog.csdn.net/initphp/article/details/30487407 Java内存分配策略 使用的ParNew+Serial Old收集器组 ...
 - tfs 2017 使用
			
安装完成之后,创建一个项目管理. 初始化代码库 然后下载代理 (服务器)并设置.下载代理需要FQ才可以下载成功. 想要支持 netcore2.0 必须在代理服务器上安装 vs2017 跟netcor ...
 - 7.5 C++基本序列式容器
			
参考:http://www.weixueyuan.net/view/6402.html 总结: vector可以理解为可以在两端插入.删除数据的数组,它提供了丰富的成员函数,用于操作数据. begin ...
 - thymeleaf之下拉框回显选中
			
#1.select下拉框取值 <div class="form-group "> <label id="resource" ...
 - JSP组件Telerik UI for JSP发布R1 2019 SP1|附下载
			
Telerik UI for JSP拥有由Kendo UI for jQuery支持的40+ JSP组件,同时通过Kendo UI for jQuery的支持能使用JSP封装包构建现代的HTML5和J ...
 - HTTPS加密原理(转)
			
Header HTTP.HTTPS在我们日常开发中是经常会接触到的. 我们也都知道,一般 Android 应用开发,在请求 API 网络接口的时候,很多使用的都是 HTTP 协议:使用浏览器打开网页, ...
 - 自定义input[type="radio"]的样式(支持普通浏览器,IE8以上)
			
对于表单,input[type="radio"] 的样式总是不那么友好,在不同的浏览器中表现不一. 对单选按钮自定义样式,我们以前一直用的脚本来实现,不过现在可以使用新的伪类 :c ...
 - mysql encode decode加密和解密
			
加密:模板:insert into user(userpass) values(encode('useerpass','str')) insert into user(userid,username, ...
 - [AOP] 之让人一脸蒙哔的面向切面编程
			
最近接触到了面向切面编程,看来很多的文档,算是有一点点了解了,趁自己还有点印象,先把它们给写出来 什么是AOP AOP(Aspect-Oriented Programming), 即 面向切面编程. ...