因开发要求,在Nginx日志中需要记录Cookie信息,以便开发查询系统发生了什么,我的日志是以json格式显示,需要在nginx.conf文件中添加如下信息:
1,#vim nginx.conf
http {
include mime.types; default_type application/octet-stream; log_format logstash_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"url":"$uri",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"agent":"$http_user_agent",' '"@req_body":"$request_body",' '"$http_cookie":"$http_cookie",' 添加这行 '"status":"$status"}';location ~* ^/test/.*$ {
proxy_hide_header Set-Cookie; 添加这行 proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://10.9.54.1:797;2,再查看Nginx日志,就可以显示Cookie信息了