environment setup
I have nginx webserver and simple backend application. this backend app has custom response header in certain condition (for example: X-Real-Status) and it's running behind nginx as an upstream (reverse proxy). now i have this custom header value with $upstream_http_x_real_status in nginx configuration.
my question is: I have two log format as below:
log_format req_format '$uri $request_method $status $request_time $http_host $upstream_response_time';
log_format req_format_v2 '$uri $request_method $upstream_http_x_real_status $request_time $http_host $upstream_response_time';
I wanna merge these two log format to one, because my custom header (upstream_http_x_real_status) not set for some situations (hosting incident, runtime error and so on) and req_format_v2 print empty rather than status (which is status of response is 504 Bad Gateway for example). I wanna have something like this in nginx configuration:
# DANGER: obviously syntax error
# ------------------------------
$real_status = $upstream_http_x_real_status | $status
log_format new_req_format '$uri $request_method $real_status $request_time $http_host $upstream_response_time';
how to achieve this purpose?
log_format req_format_v3 '$uri $request_method $status $upstream_http_x_real_status $request_time $http_host $upstream_response_time';
since all has been added, a|
letter is invalid in the configuration of nginx.