因开发要求,在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 :797;
2,再查看Nginx日志,就可以显示Cookie信息了
CentOS上安装Nginx服务器实现虚拟主机和域名重定向
CentOS 6.8 安装LNMP环境(Linux+Nginx+MySQL+PHP)
Linux下安装PHP环境并配置Nginx支持php-fpm模块
Ubuntu 16.04上启用加密安全的Nginx Web服务器