1

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

2

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

  • 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 9: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.