# Proxy\_pass by the accept header?

**URL:** <https://www.ruby-forum.com/t/proxy-pass-by-the-accept-header/215925>\
**Category:** NGINX\
**Created:** [January 19, 2012, 3:45pm UTC](https://www.ruby-forum.com/t/proxy-pass-by-the-accept-header/215925 "2012-01-19T15:45:05Z")\
**Posts on this page:** 3\
**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 19, 2012, 3:45pm UTC](https://www.ruby-forum.com/t/proxy-pass-by-the-accept-header/215925/1 "2012-01-19T15:45:05Z")

</div>

Hi all!  
I want to proxy\_pass depending on the value of the accept header. I have  
lots of locations and I wanted to add in a single place a validation  
that  
if accept header is 'text/html" it should proxy\_pass to some specific  
upstream. Else, just go ahead and try to match a location.

Is that possible?

Thanks!

Jonathan

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [January 19, 2012, 4:23pm UTC](https://www.ruby-forum.com/t/proxy-pass-by-the-accept-header/215925/2 "2012-01-19T16:23:32Z")

</div>

On 19 Jan 2012 14h44 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all! I want to proxy\_pass depending on the value of the accept  
> header. I have lots of locations and I wanted to add in a single  
> place a validation that if accept header is 'text/html" it should  
> proxy\_pass to some specific upstream. Else, just go ahead and try to  
> match a location.

> Is that possible?

Perhaps something like:

# http level

map $http\_accept $my\_upstream {  
default misc\_upstream;  
~text/html html\_upstream;

}

upstream misc\_upstream {  
server 127.0.0.1:8080;  
}

upstream html\_upstream {  
server 127.0.0.1:8088;  
}

# server level

location / {  
#… your stuff  
proxy\_pass http://$my\_upstream;  
}

— appa

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [January 19, 2012, 4:40pm UTC](https://www.ruby-forum.com/t/proxy-pass-by-the-accept-header/215925/3 "2012-01-19T16:40:20Z")

</div>

this is a great solution!  
thanks so much!
