# Conditionally set header in proxy

**URL:** <https://www.ruby-forum.com/t/conditionally-set-header-in-proxy/207079>\
**Category:** NGINX\
**Created:** [May 17, 2011, 10:15pm UTC](https://www.ruby-forum.com/t/conditionally-set-header-in-proxy/207079 "2011-05-17T22:15:07Z")\
**Posts on this page:** 2\
**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:** [May 17, 2011, 10:15pm UTC](https://www.ruby-forum.com/t/conditionally-set-header-in-proxy/207079/1 "2011-05-17T22:15:07Z")

</div>

Hello,

I’m doing SSL termination in nginx, and I’d like to set a header such as  
“X-Sheme https” ONLY if X-Scheme is not set. The reason is because an  
upstream load balancer may have terminated SSL as well, and I don’t want  
to  
overwrite that value.

Is this possible?

Best,  
Mitchell

---

<div class="post-metadata">

**Author:** ![mitchellh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8491ac/32.png) [@mitchellh](https://www.ruby-forum.com/u/mitchellh)\
**Post date:** [May 18, 2011, 6:43am UTC](https://www.ruby-forum.com/t/conditionally-set-header-in-proxy/207079/2 "2011-05-18T06:43:48Z")

</div>

On Tue, May 17, 2011 at 01:14:30PM -0700, Mitchell H. wrote:

> Hello,
> 
> I’m doing SSL termination in nginx, and I’d like to set a header such as  
> “X-Sheme https” ONLY if X-Scheme is not set. The reason is because an  
> upstream load balancer may have terminated SSL as well, and I don’t want to  
> overwrite that value.
> 
> Is this possible?

nginx-0.9.0+:

http {  
map $http\_x\_scheme $x\_scheme {  
“” https;  
default $http\_x\_scheme;  
}

```
server {

    location / {

        proxy_set_header X-Scheme $x_scheme;

```

–  
Igor S.
