揮発性のメモ2

最近知った知識を さも昔から知ってた風にメモ書きしていく

proxy_set_header でヘッダーを設定する

proxy_set_header でヘッダーを設定するとき、設定が複数個所にあると 設定されなくなることがある

server {
    proxy_set_header X-Forwarded-Proto $scheme; # ★A

    location / {
        # ★Aは有効
    }

    location /hoge {
        proxy_set_header Host $host; # ★B
        # ★Aは無効!
        # ★Bは有効
    }
}

このようにディレクティブの内と外に設定があると、外側でおこなわれた設定は無かったことになって、内側の設定のみになる。

These directives are inherited from the previous configuration level if and only if there are no proxy_set_header directives defined on the current level.

これらは、現在のレベルで proxy_set_header が定義されていない場合にのみ、前の設定レベルから継承されます

Module ngx_http_proxy_module

つまり proxy_set_header が定義されてなければ カッコの外で定義したものが引き継がれるけど
カッコの中でproxy_set_header が定義されたら、それまでの定義はすべて捨てられる。
カッコの中に入らなければ(マッチしなければ)セーフ、捨てられない。

偶然が重なってすぐ気づけたけど、普段なら死んでそうな罠だった