Nginx proxy_pass and proxy_redirect
Proxy_pass: acts as a proxy server and forwards requests
Proxy_redirect: modify the Location in the forwarding process of 301 or 302. The default is proxy_redirect default.
Example:
Location / {
Proxy_pass http://192.168.8.46:8080/; # / ending
# proxy_redirect default # this is the default value, whether it is added or not is the same.
}
In this way, it will be no problem when you proxy to port 8080 of other machines.
Location: http://192.168.8.46/4/, the url address bar of the browser is also http://192.168.8.46/4/
If:
Location / {
Proxy_pass http://192.168.8.46:8080;# removed /
Proxy_redirect off # modify the default value default to off
}
If you remove the last / later, curl-I http://192.168.8.46/4 access
Location: http://192.168.8.46:8080/4/
The address bar displayed for browser access is http://192.168.8.46:8080/4/. (if it is still the previous one, you need to delete the cache first)
As you can see, the real Location address is all exposed. At this time, you need to modify the Location using proxy_redirect.
The configuration is as follows:
Location / {
Proxy_pass http://192.168.8.46:8080;
Proxy_redirect http://192.168.8.46:8080/4/http://192.168.8.46/4/;
}
In this way, you can change the address of Location, Location: http://192.168.8.46/4/, as well as in the browser, so that information such as port number will not be exposed.
Of course, you can also get Location to other websites, such as
Proxy_redirect http://192.168.8.46:8080/4/http://www.douban.com/;
And then the browser skips.
Summary:
The man behind everything is
Proxy_pass http://192.168.8.46:8080; does not add / end, just add /, and proxy_redirect uses the default value to OK.