Score:0

Print custom header parameter's value in nginx access log

lu flag

I have a situation where consumer is passing a service a custom header parameter "Userid", I am trying to log it to nginx access log. This is what I tried and it is not working-

log_format customm '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" "[uid=$upstream_http_Userid]"';
access_log    /var/log/nginx/access.log  customm;

I also attempted these - $upstream_http_x_Userid $upstream_Userid $Userid $upstream_http_userid $upstream_userid $upstream_http_x_userid $userid and none of them worked. So I wanted to check what I am doing wrong and what is the right way to log this value to access log.

br flag
If it is a request header it should be just `$http_userid` https://nginx.org/r/$http_
datastax avatar
lu flag
@AlexeyTen This worked perfectly. Thanks for your help. If you could convert your comment to Answer I can show my gratitude by accepting the answer as the one that resolved the issue. Thanks for taking your time to respond.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.