$proxy_internal_host
$proxy_internal_host returns the hostname of the internal proxy for a request. — NGINX Core (HTTP)
Description
The $proxy_internal_host variable in NGINX is utilized primarily in configurations where requests are proxied to internal locations. Its role is to store and return the internal (or backend) hostname that is typically determined by the server’s internal network settings. This variable can be particularly useful in scenarios involving load balancing or reverse proxy setups, where multiple upstream servers might handle incoming requests. Depending on the context, this variable will be set to the internal hostname specified in the proxy configuration or defaults to the server's host if not defined explicitly. $proxy_internal_host is evaluated during the processing of a request that has been altered via proxy-related directives, such as "proxy_pass". If a proxy_name is defined, that name will be utilized as the value of this variable. If the internal hostname is not defined, it may fall back to the default behavior prescribed by the NGINX configuration. This ensures that requests are routed correctly based on either explicitly defined configurations or internal defaults. This allows advanced configurations where decisions can be made based on the $proxy_internal_host variable, enabling and managing internal routing policies or security checks based on internal hostnames. It can also enhance logging and debugging processes, where administrators may want to inspect internal proxying setups more intuitively.
Config Example
location /api {
proxy_pass http://backend_server;
proxy_set_header Host $proxy_internal_host;
}Subsystem
httpCacheable
NoContexts
http, server, locationEnsure that the internal hostname is correctly set in your proxy configurations to avoid unexpected behaviors.
$proxy_internal_host may not behave as expected if used outside of a proxy context, as it depends on proxied requests to be defined.
Remember that this variable does not include port information; if needed, it must be handled separately.