Nginx-【 配置header和cookie日志 】

1,288 阅读1分钟

需求背景

和华为联调接口,对方技术文档上要求

  • 点击华为平台跳转到应用方
  • 应用方需从华为跳转请求中获取header和cookie相关值

研发效率

  • 先在网络通过curl方式模拟联调,
  • 通过nginx日志校验header和cookie是否符合技术文档要求
  • 自测模拟通过,按技术文档coding

nginx配置

cookie日志实例

主要配置$http_cookie

   log_format  main  '$remote_addr - $remote_user [$time_local] '
                      '"$request" $status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$http_cookie"';

header日志实例

主要配置需要抓包的header项和值

image.png

  log_format  main  '$remote_addr - $remote_user [$time_local] '
                      'Authorization:"$http_Authorization" sec-ch-ua:"$http_sec_ch_ua" '
                      '"$request" $status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /home/admin/xxx/access.log  main;

模拟请求

curl -v -k -X POST \
     -H 'Content-Type: application/json' \
     -H 'Token: 1234566' \
     --cookie 'abc_session=22334455' \
     -d {"id":"111", "value":"222"} \
     http://xxx

其他配置参考

`参数                      说明                                         示例`

`$remote_addr             客户端地址                                    211.28.65.253`

`$remote_user             客户端用户名称                                --`

`$time_local              访问时间和时区                                18``/Jul/2012``:17:00:01 +0800`

`$request                 请求的URI和HTTP协议                           ``"GET /article-10000.html HTTP/1.1"`

`$http_host               请求地址,即浏览器中你输入的地址(IP或域名)     www.wang.com 192.168.100.100`

`$status                  HTTP请求状态                                  200`

`$upstream_status         upstream状态                                  200`

`$body_bytes_sent         发送给客户端文件内容大小                        1547`

`$http_referer            url跳转来源                                   https:``//www``.baidu.com/`

`$http_user_agent         用户终端浏览器等信息                           "Mozilla``/4``.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident``/4``.0; SV1; GTB7.0; .NET4.0C;`

`$ssl_protocol            SSL协议版本                                   TLSv1`

`$ssl_cipher              交换数据中的算法                               RC4-SHA`

`$upstream_addr           后台upstream的地址,即真正提供服务的主机地址     10.10.10.100:80`

`$request_time            整个请求的总时间                               0.205`

`$upstream_response_time  请求过程中,upstream响应时间                    0.002`