3

I would like to log all incoming requests, before it hits my worker nodes.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227

1 Answers1

3

I'm not sure if I understand the question ... if you want to just log HTTP access to NGINX, add the following to your virtualhost file (inside a server { } directive):

access_log /var/log/nginx/mysite.access.log main;
error_log /var/log/nginx/mysite.error.log;

Reload nginx and you'll have a typical HTTP access log.

If you want to change the log format (example: to add the response time like in the example below), you can do in /etc/nginx/nginx.conf, in the http { } block:

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

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

Note that I splitted the log_format configuration directive into several lines so that the config file is readable. Just enclose each line within single quote like done above.

Best regards

sromero
  • 757
  • 5
  • 11
  • I would like to add all the requests, coming to the proxy server. It could be authentication request, transaction request etc. Will the above configuration work ? – Saurabh Jhunjhunwala May 11 '15 at 09:31
  • Yes, the above configuration will log any GET, POST, etc request that arrives to the server, including the HTTP RESULT CODE (200 OK, 404 NOT FOUND, etc) and the response time. Just add the lines and check it in your setup. Remember to change the destination log file directory if you prefer to log to a different location or to suit your environment. – sromero May 11 '15 at 10:00
  • The config that I copy/pasted from somewhere was missing the `main` at the end of the `access_log` line, and when I added that the requests began showing up; thanks! – Scott Weldon Dec 01 '22 at 01:59