Nginx Ingress Logging Upstream Configuration
While trying to tweak the logging format of the ingress-nginx controller, I found the documentation sparse and not very helpful. Funnily enough, a random Tencent cloud page was the only one that had the actual usage and pointed me towards how to get it working.
If you deploy a stock ingress-nginx controller, it'll setup a default ConfigMap
with the name of your ingress controller. This is the one you'll want to modify.
Contrary to the Ingress-Nginx Controller documentation, you should set the key log-format-upstream
in the ConfigMap. Note that quotes in the configuration are interpreted as raw quotes in your logs. Additionally, all headers are converted to lowercase, with dashes changed to underscores.
So if you want your ingress controller to log out X-My-Special-Header
values, you'd set something like:
apiVersion: v1 data: allow-snippet-annotations: "true" enable-real-ip: "true" log-format-upstream: $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_my_special_header" kind: ConfigMap