Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an nginx-based HTTP proxy and I would like to process all HTTP redirects inside it so that clients get only the last response in the redirect chain.

The basic code looks like:

location /proxy {
    rewrite ^/proxy/([^/]+) $1 break;

    proxy_pass http://$uri/;
}

My attempt at following 1 level redirects is this:

error_page 301 302 307 =200 @redir;

... and having this named location:

location @redir {
    proxy_pass $proxy_location;
}

Only there's no $proxy_location variable and I failed to find a way of creating it. It should contain the value of Location: header received from upstream.

Any thoughts?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I believe you want the variable $upstream_http_location.

Variables that begin with $proxy* control what goes from nginx to the upstream. The $upstream* series of variables contains information about the response that nginx itself receives. You can get any aribitrary HTTP header received from an upstream server with $upstream_http_headername.

Note that these $upstream variables cannot be anything but null until the response is received from the upstream server, so there are some limitations on their use.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.