1.预设的请求头header参数:

参数名是否必填类型说明
x-auth-tokenstring登陆后返回的token
x-app-versionstringapp的版本信息
x-evi-namestring设备名称
x-evi-imeistring设备序列号
x-os-versionstring系统版本号
x-app-channellong用户的渠道号
x-user-idstring用户的userid

2.开启header下划线支持:

underscores_in_headers on;

3.nginx主配置文件配置获取header自定义信息:

  • 注意:自定义header头字段前面添加http_才能获取到输出到log

       underscores_in_headers on;
       log_format  main '$time_iso8601 $remote_addr $query_string';
       log_format normal '$remote_addr - $remote_user $time_iso8601 "$request_method 
       $scheme://$host$request_uri $server_protocol" '
             '$status $bytes_sent $request_length "$http_referer" "$http_user_agent" '
             '"$http_x_forwarded_for" $request_time $upstream_response_time'; 
       log_format logstash_json escape=json '{ "hostname": "$hostname",'
             '"log_time": "$time_local",'
             '"remote_addr": "$remote_addr",'
             '"upstream_addr": "$upstream_addr",'
             '"remote_user": "$remote_user",'
             '"body_bytes_sent": "$body_bytes_sent",'
             '"request_time": "$request_time",'
             '"status": "$status",'
             '"http_x_auth_token": "$http_x_auth_token",'
             '"http_x_app_version": "$http_x_app_version",'
             '"http_x_device": "$http_x_device",'
             '"http_x_device_name": "$http_x_device_name",'
             '"http_x_device_imei": "$http_x_device_imei",'
             '"http_x_os_version": "$http_x_os_version",'
             '"http_x_bundle_id": "$http_x_bundle_id",'
              '"http_x_app_channel": "$http_x_app_channel",'
              '"http_x_timestamp": "$http_x_timestamp",'
              '"http_x_appid": "$http_x_appid",'
              '"http_x_uid": "$http_x_uid",'
              '"upstream_response_time": "$upstream_response_time",'
              '"request_uri": "$request_uri",'
              '"server_protocol": "$server_protocol",'
              '"request_method": "$request_method",'
              '"http_referrer": "$http_referer",'
              '"http_x_forwarded_for": "$http_x_forwarded_for",'
              '"http_user_agent": "$http_user_agent",'
              '"http_cookie": "$http_cookie",'
              '"resp_body":"$resp_body",'
              '"request_body":"$request_body"}';

4.日志内容:

{ "hostname": "hw_yuwan_web_01","log_time": "28/Aug/2019:22:01:38 +0800",
"remote_addr": "123.134.220.122","upstream_addr": "10.123.0.12:8090","remo
te_user": "","body_bytes_sent": "326","request_time": "0.005","status": "200","h
ttp_x_auth_token": "B884174893134014B9251A1F91C59FFF","http_x_app_versi
on": "1.1.8","http_x_device": "2","http_x_device_name": "PAR-AL00","http_x_de
vice_imei": "d5e53def2caeacba7780664e62168a5e","http_x_os_version": "9","ht
tp_x_bundle_id": "com.xianlai.social","http_x_app_channel": "360","http_x_tim
estamp": "3134004924","http_x_appid": "","http_x_uid": "","upstream_response_
time": "0.005","request_uri": "/version/refresh","server_protocol": "HTTP/1.1","
request_method": "GET","http_referrer": "","http_x_forwarded_for": "106.118.5
8.41","http_user_agent": "okhttp/3.9.1","http_cookie": "","resp_body":"{\"meta\"
:{\"message\":\"操作成功\",\"code\":\"2000\"},\"data\":{\"id\":\"\",\"appType\":\"2\"
,\"appVersion\":\"3.3.0\",\"downloadUrl\":\"https://m.xadsaf.com/download/xid
fasd.apk\",\"upFlag\":\"1\",\"upTitle\":\"发现新版本\",\"upDesc\":\"本\",\"upTime\":\
"\",\"creator\":\"\",\"createdDate\":\"\"}}","request_body":""}
Last modification:September 9th, 2019 at 09:55 pm
如果觉得我的文章对你有用,请随意赞赏