R
R
rocket_b2020-09-21 14:58:05
Nginx
rocket_b, 2020-09-21 14:58:05

How to redirect inside proxy_pass in nginx?

location added to nginx for https://examle.com/

: location /test/ {
proxy_pass proxy:5601 ;
proxy_redirect off;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
}

When you go to https://examle.com/test , proxy_pass is triggered, inside proxy:5601 redirection to proxy:5601/app/page is triggered and in the browser we see the link https://examle.com/app/page/, respectively, nginx does not know this location, how to correctly set location so that redirects inside proxy_pass work out?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-09-21
@Nc_Soft

https://nginx.org/ru/docs/http/ngx_http_proxy_modu...
If the URI is changed inside the proxied location using the rewrite directive, and the request will be processed with this configuration (break):

location /name/ {
    rewrite    /name/([^/]+) /users?name=$1 break;
    proxy_pass http://127.0.0.1;
}

In this case, the URI specified in the directive is ignored, and the entire modified request URI is sent to the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question