proxy_pass by the accept header?

António P. P. Almeida appa at
Thu Jan 19 15:22:33 UTC 2012

On 19 Jan 2012 14h44 WET, ionathan at 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 {

upstream html_upstream {

# server level

location / {
    #... your stuff
    proxy_pass http://$my_upstream;

--- appa

More information about the nginx mailing list