$proxy_add_via

The $proxy_add_via variable is used to append a 'Via' header to HTTP requests being proxied in NGINX. — NGINX Core (HTTP)

$proxy_add_via NGINX Core (HTTP)

Description

The $proxy_add_via variable is dynamically generated by NGINX when an HTTP request is proxied to another server. It constructs a 'Via' header that helps identify the proxying method used. This variable is typically set to the format '1.1 NGINX' when the request is proxied, indicating the version of the protocol used along with the server name. This is particularly useful for debugging and managing caching systems, as it allows client applications and intermediate proxies to trace back the request through the NGINX proxy. This variable is usually set when using the proxy_pass directive in the configuration. For instance, if the `proxy_pass` directive is configured properly for an upstream server, NGINX will automatically populate $proxy_add_via with the appropriate value for all requests forwarded to that server. If multiple proxies are chained, the 'Via' headers will reflect the entire route the request has taken, enabling better control and visibility into shared caches and routing mechanisms. Typical values might include '1.1 NGINX' or indicate additional proxy services if they are being used alongside NGINX.

Config Example

location /api {
    proxy_pass http://backend_service;
    proxy_set_header Host $host;
    add_header Via $proxy_add_via;
}

Subsystem

http

Cacheable

Yes

Contexts

http, server, location

Ensure that the 'add_header' directive includes the appropriate context for the header to show up in responses (e.g. using `always` if necessary).

The 'Via' header can expose sensitive server information, ensure that this is considered when configuring public-facing proxies.

When running multiple NGINX instances, each may append its 'Via' header leading to a long chain if not managed properly.