Is there a way in which user-name or user-id can be stored in nginx logs. I tried inserting $remote_user in the log_format directive but it doesn't seem to work.
Yes, this is possible. However, since you aren't using HTTP basic auth, you will need your application to tell Nginx what the current username is. Add a response header along the lines of:
Then in your
I also recommend removing this extra header from the response before sending it to the client. You can do this with the NginxHttpHeadersMoreModule.