這個比較方便,直接在nginx.conf文件中添加$http_cookiehtml
log_format main '[$time_local] - $remote_addr:$remote_port - $remote_user - $upstream_addr $upstream_status $upstream_response_time - ' '"$request" $status $bytes_sent $request_time ' '"$http_referer" - "$http_user_agent" ' '"$http_cookie"'; # 增長一個 $http_cookie
第二步,在server 中的access.log 後加上 mainnginx
access_log logs/item_access.log main; error_log logs/item_error.log ;
有時候要是是以爲某個cookie很重要,須要單獨取出來,省得去一堆麻煩cookie
首先,也是在nginx.conf文件中定義一個值,如 $my_cookie 日誌
log_format main '[$time_local] - $remote_addr:$remote_port - $remote_user - $upstream_addr $upstream_status $upstream_response_time - ' '"$request" $status $bytes_sent $request_time ' '"$http_referer" - "$http_user_agent" ' '"$my_cookie" "$http_cookie"'; # 這邊定義了 $my_cookie 和 $http_cookie其實都能取到 # $my_cookie只能取到 value
其次仍是要改server 中的內容,orm
server { listen 80; server_name XXXX.****.com ; access_log logs/item_access.log main; # main 須要 error_log logs/item_error.log ; set $my_cookie ""; if ($http_cookie ~* "my_cookie=(.+?)(?=;|$)") { set $my_cookie $1; }
若是以爲不止一個cookie的值重要,好比有兩個cookie須要取出來,如何呢?重複第二步的動做server
log_format main '[$time_local] - $remote_addr:$remote_port - $remote_user - $upstream_addr $upstream_status $upstream_response_time - ' '"$request" $status $bytes_sent $request_time ' '"$http_referer" - "$http_user_agent" ' '"$my_cookie" - "$my_cookie2" - "$http_cookie"';
server { listen 80; server_name XXXX.***.com ; access_log logs/item_access.log main; # main 須要 error_log logs/item_error.log ; set $my_cookie ""; if ($http_cookie ~* "my_cookie=(.+?)(?=;|$)") { set $my_cookie $1; } set $my_cookie2 ""; if ($http_cookie ~* "my_cookie2=(.+?)(?=;|$)") { set $my_cookie2 $1; }
我這邊是實現了,可是命名不同,你們本身嘗試吧。htm