Scolytus
Scolytus

Reputation: 17137

modify HTTP status code of proxy result in nginx

I have a nginx reverse proxy serving a web application. This web app returns a 302 redirect in some cases and I can't change it. However, for some reasons I need to change this returned status to be 301.

I tried

proxy_intercept_errors on;
error_page 302 =301;

but obviously this the =301 part as the new location. So what I'm looking for would be something like this:

proxy_intercept_errors on;
error_page 302 =301 $PROXY_HEADER_LOCATION;

How can I do this?

Upvotes: 4

Views: 3921

Answers (1)

Scolytus
Scolytus

Reputation: 17137

The header fields of the upstream server are accessible through $upstream_http_*

So this worked for me:

proxy_intercept_errors on;
error_page 302 =301 $upstream_http_location;

Upvotes: 3

Related Questions