Nginx Proxy Headers, HTTP Versions and Timeouts
Choose the upstream Host deliberately
The backend may serve multiple applications, so its Host value matters. With ordinary HTTP/1.x proxying, Nginx normally substitutes the destination host and port. Some apps need the original public name; others need a fixed internal name. Decide with the application owner.
location /catalog/ { proxy_pass http://127.0.0.1:18122; proxy_http_version 1.1; proxy_set_header Host catalog.test; proxy_set_header Connection close;}The catalog receives Host: catalog.test and HTTP/1.1 even if the frontend uses a different hostname. Nginx versions before 1.29.7 defaulted to HTTP/1.0 upstream; from 1.29.7 the default is 1.1. Upstream HTTP/2 support was introduced in 1.29.4 and needs the HTTP/2 module; it is not used in this lab. The client-side HTTP version does not automatically choose the upstream version.
This alternative passes the selected request hostname (with a fallback). Only use it with a validated host policy and a backend that expects it. $http_host is the incoming Host field, which may contain a port or be absent. $host is not an authorization decision.
Forwarded information is a trust boundary
proxy_set_header Host catalog.test;proxy_set_header Connection close;proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Real-IP "";proxy_set_header Forwarded "";proxy_set_header X-Forwarded-Host "";For this direct-client lab, the proxy replaces the address and scheme claims and removes other listed forwarding fields. The app must accept these values only from its trusted proxy and ignore unapproved aliases. If a trusted load balancer sits before Nginx, the immediate peer is not necessarily the original client; configure a separate trust policy before accepting a chain. Adding to an untrusted incoming chain does not make it authentic. Header settings from a parent are inherited only when the child defines none of its own proxy_set_header directives. Keep the whole intended policy together.
Three clocks for three operations
proxy_connect_timeout 2s;proxy_send_timeout 3s;proxy_read_timeout 3s;Connect covers opening the upstream connection, send covers stalled writes of the request, and read covers stalled reads of the response. The send and read limits measure inactivity between operations, not the total request duration. A response that keeps sending data can last longer than the read timeout. These values are for a tiny local fixture, not production recommendations.
Backend returns 404 → normally client gets 404Backend refuses connection → commonly 502Backend stalls before response headers beyond read limit → commonly 504A timeout after headers have reached the client may instead produce an incomplete response. Retries, interception, and other configuration can change the final outcome. In this lab there is one destination per location, no retry and no error interception for the app. Do not solve every delay by increasing all limits: inspect timing, backend health and application expectations first.
Practice: explain why a 3-second read timeout does not promise a 3-second response deadline; then inspect the lab header policy. Next chapter: combine static and proxied sites into one hosting milestone.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Upstream headers and timeouts
Choose the best answer based on the lesson and local fixture.
Which setting selects the HTTP version on the app connection?
Why explicitly replace X-Forwarded-For at this direct-client edge?
A location adds one proxy_set_header. What about parent header settings?
Which timeout addresses silence while receiving a response?
A backend returns an ordinary 404, with interception off. What should the client normally get?