How to enable nginx debug logging?

enable-nginx-debug-logging

In this article we will explain how to enable Nginx debug logging .
To enable debugging in NGINX, you will need to compile/recompile Nginx with the “–with-debug” flag specified in the configure script.

1 2 3 4 5   [root@test.test.com nginx1.11.9]# ./configure –help |grep debug withdebug enable debug logging [root@test.test.com nginx1.11.9]#  

Now compile nginx with “–with-debug” flag

1 2 3 4 5   ./configure withdebug ; make make install  

Now we will see how to enable nginx debug logging

Writing Nginx Debugging Log to a File

The debugging log records errors and any debugging-related information and is disabled by default. To enable it, you will have to recompile nginx with

“–with-debug” flag.
Then add following line in the nginx configuration file /etc/nginx/nginx.conf

1 2 3   vi /etc/nginx/nginx.conf  

Locate the “error_log” directive and set the log level to debug

1 2 3   error_log /var/log/nginx/error.log debug;  

Restart Nginx once done.

1 2 3 4 5 6   [root@test.test.com nginx1.11.9]# /etc/init.d/nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] [root@test.test.com nginx1.11.9]#  

Now you can check the log file “/var/log/nginx/error.log” using tail

1 2 3   tail f /var/log/nginx/error.log  

Sample logs are below

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30   2017/03/22 12:35:15 [debug] 2940#0: timer delta: 140 2017/03/22 12:35:15 [debug] 2940#0: posted event 0000000000D72C90 2017/03/22 12:35:15 [debug] 2940#0: *2 delete posted event 0000000000D72C90 2017/03/22 12:35:15 [debug] 2940#0: *2 http keepalive handler 2017/03/22 12:35:15 [debug] 2940#0: *2 malloc: 0000000000CA4980:1024 2017/03/22 12:35:15 [debug] 2940#0: *2 recv: fd:17 779 of 1024 2017/03/22 12:35:15 [debug] 2940#0: *2 reusable connection: 0 2017/03/22 12:35:15 [debug] 2940#0: *2 posix_memalign: 0000000000CAFDC0:4096 @16 2017/03/22 12:35:15 [debug] 2940#0: *2 event timer del: 17: 1490186180391 2017/03/22 12:35:15 [debug] 2940#0: *2 http process request line 2017/03/22 12:35:15 [debug] 2940#0: *2 http request line: “GET /favicon.ico HTTP/1.1” 2017/03/22 12:35:15 [debug] 2940#0: *2 http uri: “/favicon.ico” 2017/03/22 12:35:15 [debug] 2940#0: *2 http args: “” 2017/03/22 12:35:15 [debug] 2940#0: *2 http exten: “ico” 2017/03/22 12:35:15 [debug] 2940#0: *2 http process request header line 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “Host: 192.168.2.21” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “Connection: keep-alive” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “Accept: image/webp,image/*,*/*;q=0.8” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “Referer: http://192.168.2.21/” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “Accept-Encoding: gzip, deflate, sdch” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “Accept-Language: en-US,en;q=0.8,ml;q=0.6” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header: “Cookie: __test=1; AJS.conglomerate.cookie=”|config.sidebar.planNavigator.expanded=true|config.sidebar.branchNavigator.expanded=true”; bamboo.dash.display.toggles=buildQueueActions-actions-queueControl; m=34e2:|4e99:t; uchiwa_theme=uchiwa-dark; csrftoken=TsDazmw0V0A9tXa8YIezuI5BdFuhrxJQ; splunkweb_csrf_token_8000=12844391238768912208; grafana_user=admin; grafana_remember=2cb0b586bc2d1de065b6f7f5efa260b658e980c30ffe5eae” 2017/03/22 12:35:15 [debug] 2940#0: *2 http header done 2017/03/22 12:35:15 [debug] 2940#0: *2 generic phase: 0 2017/03/22 12:35:15 [debug] 2940#0: *2 rewrite phase: 1 2017/03/22 12:35:15 [debug] 2940#0: *2 test location: “/” 2017/03/22 12:35:15 [debug] 2940#0: *2 test location: “50x.html”  

SUMMARY

In this article we explained how to enable nginx debug logging on a Linux Machine.

As always,Please drop us a note if you have any questions or feedback using our comment form below . Always Happy to Help ????

Author: , 0000-00-00