【Nginx】Nginx配置Json格式日志


nginx.conf 模塊配置 log_format:

log_format main '{
  "@timestamp":"$time_iso8601",
  "host":"$server_addr",
  "clientip":"$remote_addr",
  "remote_user":"$remote_user",
  "request":"$request",
  "http_user_agent":"$http_user_agent",
  "size":"$body_bytes_sent",
  "responsetime":"$request_time",
  "upstreamtime":"$upstream_response_time",
  "upstreamhost":"$upstream_addr",
  "http_host":"$host",
  "url":"$uri",
  "domain":"$host",
  "xff":"$http_x_forwarded_for",
  "referer":"$http_referer",
  "status":"$status"
}';

 

配置完成后執行下格式校驗:../sbin/nginx -t

校驗成功后,重新加載配置:../sbin/nginx -s reload

日志展示如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM