log_format cntr escape=json '{"time":"$time_local",'
'"@source":"$server_addr",'
'"hostname":"$hostname",'
'"xforward":"$http_x_forwarded_for",'
'"remoteaddr":"$remote_addr",'
'"method":"$request_method",'
'"scheme":"$scheme",'
'"domain":"$server_name",'
'"referer":"$http_referer",'
'"requrl":"$request_uri",'
'"args":"$args",'
'"requestbody":"$request_body",'
'"contentlength":"$content_length",'
'"bodybytessend":$body_bytes_sent,'
'"status":$status,'
'"requesttime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamaddr":"$upstream_addr",'
'"respbody":"$resp_body",'
'"respdown":"$resp_ctrl_down",'
'"useragent":"$http_user_agent"'
'}';
location /abc {
#access_log off;
access_log /data/logs/nginx/abc/access.log cntr buffer=32k flush=5s;
error_log /data/logs/nginx/abc/error.log info;
set $resp_ctrl_down -1;
set $resp_body "";
# only elk collection machine, can add the below lua code.
body_filter_by_lua_block {
local chunk, eof = ngx.arg[1], ngx.arg[2]
ngx.var.resp_body=ngx.var.resp_body..chunk
if eof then
if string.find(ngx.var.resp_body,'"count":true') then
ngx.var.resp_ctrl_down = 1
else
ngx.var.resp_ctrl_down = 0
end
end
}
proxy_pass http://abc/flow;
}
月度归档:2019年04月
Centos7屏蔽防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
nginx日志格式
access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]]; # 设置访问日志
access_log off; # 关闭访问日志