Nginx forwarding configuration
Nginx configures proxy_pass forwarding / path issues
When configuring proxy_pass in nginx, if you match the path according to ^ ~, you should pay attention to the last / of the url after proxy_pass. When / is added, which is equivalent to the absolute root path, nginx will not take part of the matching path in location as an agent; if there is no /, it will also give the matching part of the path to the agent.
Location ^ ~ / static_js/
{
Proxy_cache js_cache
Proxy_set_header Host js.test.com
Proxy_pass http://js.test.com/;
}
As configured above, if the requested url is http://servername/static_js/test.html
Will be represented as http://js.test.com/test.html.
And if configured in this way,
Location ^ ~ / static_js/
{
Proxy_cache js_cache
Proxy_set_header Host js.test.com
Proxy_pass http://js.test.com;
}
Will be represented to http://js.test.com/static_js/test.htm
Of course, we can use the following rewrite to achieve /
Location ^ ~ / static_js/
{
Proxy_cache js_cache
Proxy_set_header Host js.test.com
Rewrite / static_js/ (. +) $/ $1 break
Proxy_pass http://js.test.com;
}