Skip to content
The Chat Archive
o4-mini-2025-04-16· OpenAI LMArena Human Preference 140K

proxypassheader vs proxysetheader in nginx

  1. User

    proxy_pass_header vs proxy_set_header in nginx

  2. Assistant

    Here’s the short version:

    • proxy_set_header
      • Controls which headers NGINX sends (or overrides) when forwarding a request to your upstream (backend) server.
      • Commonly used to pass client info (e.g. Host, X‑Forwarded‑For, etc.).

    • proxy_pass_header
      • Controls which headers NGINX forwards back from your upstream server’s response to the client.
      • By default, only a handful of “safe” headers (Date, Server, etc.) are passed; use this to expose additional ones.


    1. proxy_set_header

    Use when you want to add or overwrite request headers sent from NGINX → upstream.

    location / {
        proxy_pass         http://backend;
        proxy_set_header   Host              $host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        # …you can set any header name = value
    }
    

    Common use‑cases
    • Preserve original Host (for vhost/backends)
    • Track client IP via X‑Forwarded‑For
    • Pass along authentication tokens, custom flags, etc.


    2. proxy_pass_header

    Use when you want to whitelist additional response headers to propagate from upstream → client. By default NGINX strips most headers except a few “safe” ones (Date, Server, etc.).

    location /files/ {
        proxy_pass          http://storage;
        # Ask NGINX to forward the “X-Accel-Redirect” header it got from storage
        proxy_pass_header   X-Accel-Redirect;
        # You can repeat for other headers:
        proxy_pass_header   Content-Disposition;
        proxy_pass_header   X-Custom-Header;
    }
    

    Common use‑cases
    • Implementing X-Accel-Redirect / X-Accel-Buffering workflows
    • Preserving upstream‑set Cache‑Control or ETag headers
    • Exposing custom metadata in response headers


    Summary Table

    DirectiveDirectionDefault behaviorTypical use
    proxy_set_headerNGINX → upstreamNone (overwrites only)Forward client IP, Host, auth‑tokens
    proxy_pass_headerupstream → clientStrips most extrasExpose ETag, Cache‑Control, redirects

    ❓ Got a specific scenario in mind—e.g. passing along auth headers or handling file downloads? Let me know, and I can tailor the config!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.