Nginx upstream name in log format

loggingnginx

Is there a way to use the upstream name in the nginx log format instead of the specific upstream node host/ip address used for handling a request ?

$upstream_addr is the variable to use for the specific node, and will give the name of the group when no functioning nodes are present. I want to always log the name of the upstream group itself, though.

I can't find anything about it in the official documentation, but perhaps there's an undocumented variable, compile option or module that makes it possible ?

Best Answer

You could use $proxy_host variable. It contains host name specified in proxy_pass directive. In your case it's exactly upstream name.

Related Topic