NGINX proxy_pass or proxy_redirect

Need help on Nginx proxy_pass.

From outside Nginx URL will be hit like this: ?.....

my downstream service looks like this: ?...

I want to get rid of

/v2/platform/general

from original public url and call my downstream service like above.

In Nginx, how do I redirect public access URL to downstream service?

I tried this:

location /v2/platform/general/ { rewrite ^/(.*) /$1 break; proxy_redirect off; proxy_pass proxy_set_header Host $host; 

But it didn't work, any help appreciated.

1 Answer

proxy_pass and proxy_redirect have totally different functions. The proxy_redirect directive is only involved with changing the Location response header in a 3xx status message. See this document for details.

Your rewrite statement does nothing other than prevent further modification of the URI. This line needs to be deleted otherwise it will inhibit proxy_pass from mapping the URI. See below.

The proxy_pass directive can map the URI (e.g. from /v2/platform/general/foo to /foo) by appending a URI value to the proxy_pass value, which works in conjunction with the location value. See this document for details.

For example:

location /v2/platform/general/ { ... proxy_pass } 

You may need to set the Host header only if your upstream server does not respond correctly to the value another-IP:8080.

You may need to add one or more proxy_redirect statements if your upstream server generates 3xx status responses with an incorrect value for the Location header value.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like