# Proxy\_set\_header at http level

**URL:** <https://www.ruby-forum.com/t/proxy-set-header-at-http-level/201341>\
**Category:** NGINX\
**Created:** [January 5, 2011, 3:44pm UTC](https://www.ruby-forum.com/t/proxy-set-header-at-http-level/201341 "2011-01-05T15:44:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 5, 2011, 3:44pm UTC](https://www.ruby-forum.com/t/proxy-set-header-at-http-level/201341/1 "2011-01-05T15:44:12Z")

</div>

Hi all,

Although the documentation (  
[Module ngx\_http\_proxy\_module](http://wiki.nginx.org/HttpProxyModule#proxy_set_header)) says the context  
of  
proxy\_set\_header can be http, server, location，we found that  
proxy\_set\_header directive at http level does not work. When moved to  
server  
level, everything works fine.

Setting proxy\_set\_header at http level allows us to centralize some  
common  
settings thus avoid manually copy those directives to each virtual host  
when  
it was created. e.g., we use X-Http-Scheme header to let backend server  
know  
if it’s a https request, otherwise they can’t know.

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [January 5, 2011, 6:10pm UTC](https://www.ruby-forum.com/t/proxy-set-header-at-http-level/201341/2 "2011-01-05T18:10:35Z")

</div>

Hello!

On Wed, Jan 05, 2011 at 10:42:09PM +0800, 杨镭 wrote:

> it was created. e.g., we use X-Http-Scheme header to let backend server know  
> if it’s a https request, otherwise they can’t know.

It works at http level just fine. Most likely you’ve defined  
proxy\_set\_header at server level as well, and this cleared  
values set on http level. Note the following in wiki:

% proxy\_set\_header directives issued at higher levels are only  
% inherited when no proxy\_set\_header directives have been issued at  
% a given level

Maxim D.

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [January 6, 2011, 3:25pm UTC](https://www.ruby-forum.com/t/proxy-set-header-at-http-level/201341/3 "2011-01-06T15:25:13Z")

</div>

Hi,

Thanks. I did some tests:

(A) Set X-AAA at http level and do nothing at server level.  
OK.

(B) Set X-AAA at http level and set X-BBB at server level.  
Only X-BBB is set and sent to backend.

So the inheritance mechanism of proxy\_set\_header works in a All-None  
mode.  
If there is any directive set at a smaller block, all the values set by  
bigger block are cancelled.

Is it possible to change this behavior to the normal inheritance  
mechanism  
so setting directive at smaller block only cancel the same directive at  
bigger block?

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [January 6, 2011, 3:56pm UTC](https://www.ruby-forum.com/t/proxy-set-header-at-http-level/201341/4 "2011-01-06T15:56:37Z")

</div>

Hello!

On Thu, Jan 06, 2011 at 10:23:45PM +0800, 杨镭 wrote:

> So the inheritance mechanism of proxy\_set\_header works in a All-None mode.  
> If there is any directive set at a smaller block, all the values set by  
> bigger block are cancelled.

Yes. This is how it works for all array-type directives.

> Is it possible to change this behavior to the normal inheritance mechanism  
> so setting directive at smaller block only cancel the same directive at  
> bigger block?

No.

Maxim D.
