zoukankan      html  css  js  c++  java
  • Nginx更改日志格式为json

      这里只是简单记录一下主配置文件中的format格式,因为在配置过程中一直不生效,最后发现是因为配置尾部没有加 号导致,所以这里简单做一个记录。

    #/etc/nginx/nginx.conf
    user nginx; worker_processes auto; error_log
    /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; #main只是一个引用名称,在access_log是引用的,名称可以改成任意 log_format main '{"nginx_timestamp":"$time_iso8601","clientip":"$remote_addr", ' '"nginx_host":"$server_addr","host":"$http_host","request":"$request","url":"$request_uri",' '"upstreamhost":"$upstream_addr","status":"$status","body_bytes_sent":"$body_bytes_sent",' '"request_time":"$request_time","upstream_response_time":"$upstream_response_time",' '"xff":"$http_x_forwarded_for","referer":"$http_referer","http_user_agent":"$http_user_agent",' '"request_length":"$request_length","request_method":"$request_method"}'; #配置文件尾部没有加上分号,nginx -t检测没有异常,但是format日志一直不生效,需注意。 access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }

      在Nginx的配置文件/etc/nginx/nginx.conf中,定义了日志格式:main,这个main只是一个引用名称,在配置日志的时候指定即可,当然使用这种方式可以配置几种不同的日志格式。

      access_log  /var/log/nginx/access.log  main;

    作者:小家电维修

    相见有时,后会无期。

  • 相关阅读:
    分形与数据结构第一篇(神奇的色子)
    画图小工具第二篇
    画图小工具第一篇
    图形界面第一篇
    回合制对战游戏第二篇
    回合对战制游戏第一篇(初识java)
    技术+态度+人品
    排序的一些方法(稳定性,内外排序,时间空间复杂度)
    暂时性死区
    vue传值(父子传值,非父子传值)
  • 原文地址:https://www.cnblogs.com/lizexiong/p/14989934.html
Copyright © 2011-2022 走看看