Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.19.5-3

* Set or forward `X-Request-ID`.
* Add computed `X-Request-ID` to the access logs.

## 1.19.5-2

* Forward `X-Forwarded-*` headers to upstream correctly.
Expand Down
8 changes: 8 additions & 0 deletions config/http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ http {
'' $server_port;
}

# If we receive X-Request-ID, pass it through; otherwise, pass along the
# request_id generated by nginx
map $http_x_request_id $proxy_x_request_id {
default $http_x_request_id;
'' $request_id;
}

proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
Expand All @@ -39,6 +46,7 @@ http {
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
proxy_set_header X-Request-ID $proxy_x_request_id;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some apps like Rails with use this as the request_id if the X-Request-ID exists. Else, they generate one. So it's certainly useful to set it here because it will be used upstream. See ...

Screenshot 2021-02-10 at 12 01 48

proxy_set_header X-Forwarded-Host $host;

proxy_read_timeout 600s;
Expand Down
2 changes: 1 addition & 1 deletion config/log.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
'"$http_user_agent" "$http_x_forwarded_for" $proxy_x_request_id';
Comment on lines 1 to +3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to improve this log format to have a little more information but I think that's best done in another PR. Using the Kubernetes Ingress - Ingress log format as inspiration ...

log_format upstreaminfo
    '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" "$http_user_agent" '
    '$request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr '
    '$upstream_response_length $upstream_response_time $upstream_status $req_id';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get behind this 👌

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to improve this log format to have a little more information but I think that's best done in another PR. Using the Kubernetes Ingress - Ingress log format as inspiration ...

Done in #6.


access_log /dev/stdout main;
error_log /dev/stdout warn;