NGINX proxy_pass or proxy_redirect

bluelabel

Need help on Nginx proxy_pass.

From outside Nginx URL will be hit like this: http://some-IP:8080/v2/platform/general/activity/plan?.....

my downstream service looks like this: http://another-IP:8080/activity/plan?...

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 http://another-IP:8080;
  proxy_set_header Host $host;

But it didn't work, any help appreciated.

Richard Smith

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 http://another-IP:8080/;
}

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related