---
title: "Discussion on \"How a Duplicate `proxy_set_header Host` Caused an Nginx 400 Bad Request\" | Hashnode"
description: "Discussion on \"How a Duplicate `proxy_set_header Host` Caused an Nginx 400 Bad Request\". I recently hit an Nginx 400 Bad Request while routing selected production traffic to a pre-production backend.\nThe setup was roughly:\nClient\n  |\n  v\nCDN / Load Balancer\n  |\n  v\nProduction Nginx\n  |"
url: "https://hashnode.com/posts/how-a-duplicate-proxy-set-header-host-caused-an-nginx-400-bad-request/6abe1d6b90fdc2a395fa47f3"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How a Duplicate \`proxy\_set\_header Host\` Caused an Nginx 400 Bad Request](https://calvinleung.hashnode.dev/how-a-duplicate-proxy-set-header-host-caused-an-nginx-400-bad-request?utm_source=hashnode&utm_medium=feed)

I recently hit an Nginx 400 Bad Request while routing selected production traffic to a pre-production backend. The setup was roughly: Client | v CDN / Load Balancer | v Production Nginx |

Oct 1 · 3 min read · calvinleung.hashnode.dev  
Updated Oct 23  
Read the article

-   [#nginx](https://hashnode.com/tag/nginx)

## Written by

[Calvin Leung](https://hashnode.com/@calvinleung)

@calvinleung · Singapore

  
[View profile](https://hashnode.com/@calvinleung)

Sharing experience of real-world cloud operations

## Responses 1

Markdown supported · ⌘↵ to post

[Edge Ops](https://hashnode.com/@edgecacheops)

[Oct 31](https://hashnode.com/posts/how-a-duplicate-proxy-set-header-host-caused-an-nginx-400-bad-request/6abe1d6b90fdc2a395fa47f3/comment/6ae585289aa65507bf65a9fd)

Sharp write-up of a classic inheritance footgun: a second proxy\_set\_header Host in a nested location silently replaces the parent set instead of merging, so the upstream sees a wrong or empty Host and answers 400 while the edge looks healthy. I treat Host as a single source of truth per request path — set it once at the outermost proxy location (or map it), never redeclare it in an include that also wraps canary or preprod upstreams. Same rule for X-Forwarded-Proto: one clear value from the terminating edge, not a second overwrite deeper in.

After any traffic-split change I dump the effective config for that server block and grep every proxy\_set\_header Host line before reload. Then I hit the canary upstream with the intended Host and again through the public name, comparing status and the Host the app logged. Mismatch almost always means a nested location redeclared the header, not a bad certificate or DNS. Keep a short checklist of which locations are allowed to touch Host so the next shadow deploy does not reintroduce the duplicate.
