$http_via

The $http_via variable retrieves the value of the 'via' header sent by upstream proxies in HTTP requests. — NGINX Core (HTTP)

$http_via NGINX Core (HTTP)

Description

The `$http_via` variable in NGINX is used to access the value of the 'via' header from an HTTP request. This header is typically added by web proxies to indicate the intermediary servers through which the request has passed, providing insight into the request's routing and any caching mechanisms involved. When a client sends a request through one or more proxies, the 'via' header is appended by each proxy, concatenating the information, and allowing the downstream servers to analyze the request path. Setting this variable occurs automatically when NGINX processes the headers of incoming requests. If the 'via' header is present, `$http_via` will hold its value, which can include multiple pieces of information if the request has traversed several proxies. Common values for this header might include details such as the software of the proxy server and its version. If the request does not have a 'via' header, the variable will be empty, allowing for conditional logic in your server configuration based on the presence of this header.

Config Example

server {
    listen 80;
    location / {
        if ($http_via) {
            add_header X-Proxy-Server $http_via;
        }
        proxy_pass http://backend;
    }
}

Subsystem

http

Cacheable

Yes

Contexts

http, server, location, if

Ensure that the 'via' header is actually appended by the upstream proxies; otherwise, the variable will be empty.

Be cautious of relying on the presence of `$http_via` for security or access control, as any client could spoof HTTP headers in requests sent directly to the server.