Sunday, October 19, 2014

How to change the logging pattern of Nginx

Some time you may needs to filter out requests and responses coming to Nginx with more details wich requires specify customize log level in Nginx. Assume you may needs to find out the JSESSIONID of a request coming to the Nginx. Here is the way to have the customize log with Nginx.

Specify following logging format in the nginx.conf and refer it in the access log.

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


access_log /var/log/nginx/access.log main;

You will see out put similar to follow.

10.100.5.81 - - [29/Sep/2014:15:44:06 +0530]  "GET /gad_test/index.jsp HTTP/1.1" 200 147 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36" - "JSESSIONID=A2EADE2B419119B8D6184D2B403EC1F1; menuPanel=visible; menuPanelType=main; MSG14119741284050.4971712792784695=true; MSG14119785293260.851528721338783=true; MSG14119793691950.3470202483511987=true; MSG14119793844710.6098322352974117=true; requestedURI=\x22../../carbon/webapp-mgt/upload.jsp?region=region1&item=webapps_add\x22; current-breadcrumb=manage_menu%2Cwebapps_menu%2Cwebapps_list_menu%23webapp-list+webapp_info.jsp*; JSESSIONID=AB2D16E5754D07F20584BBC58119B466"
Also you can enable debug logs of Nginx as follow
error_log path_to_the_log_file debug;

No comments:

Post a Comment