proxy_redirect
Syntax: proxy _ redirect [default | off | redirect replacement];
Default: proxy_redirect default;
Configuration blocks: http, server, location
When the response returned by the upstream server is a redirect or refresh request (for example, the HTTP response code is 301 or 302), proxy_redirect can reset the location or refresh field of the HTTP header.
location /login {
proxy_pass http://target_servers/login ;
}
Assume that the current nginx access address ishttp://192.168.99.100:8080If target_servers has 302 to 192.168.99.100/xxx
Then you can add a redirect and change the location of 302 tohttp://192.168.99.100:8080/xxx
location /login {
proxy_pass http://target_servers/login ;
proxy_redirect http://192.168.99.100/ http://192.168.99.100:8080/;
}
Host variable
If you do not want to write a dead ip address, you can use the variable nginx
location /login {
proxy_pass http://target_servers/login ;
proxy_redirect http://$host/ http://$http_host/;
}
Where host does not have a port, that is, the host ip deployed by nginx, and $http_host has a port