Note: I gave this answer before the OP added tag openresty
. I am not an expert in Openresty, but I am sure I gave correct details in case of vanilla Nginx.
A "backend server" is called "upstream" in Nginx terminology. And there is a separate page in the documentation that lists variables associated w/ upstreams. Among them, you will probably be interested in
$upstream_addr
– IP address of an backend server that processed the request
$upstream_connect_time
, $upstream_header_time
, $upstream_response_time
– how long Nginx waited for connection accept, for header from the upstream and how long did it take for the backend to process the request
$upstream_http_*NAME*
will contain the response header *NAME*
. For example, $upstream_http_etag
or $upstream_http_last_modified
.
- there are other variables to report caching status, retries, etc.
It's quite common practice to log these into Nginx log file. You will need to declare your own log format, for example:
log_format my_upstream '$remote_addr [$time_local] "$request" $status'
'"$upstream_addr" $upstream_response_time $upstream_http_etag';
and then use it in location
or server
:
access_log /var/log/nginx/upstream.log my_upstream;
upstream_*
value always displays-
. e.g.upstream_addr
,upstream_http_host
, andupstream_connect_time
– Chandlery