nginx url 转发 修改访问路径
在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。
1 |
|
如上面的配置,如果请求的url是http://www.wekri.com/docker/introduction/what.html
会被代理成http://127.0.0.1:4000/introduction/what.html
而如果这么配置
1 |
|
则会被代理到http://127.0.0.1:4000/docker/introduction/what.html
当然,我们可以用如下的rewrite来实现/的功能
1 |
|
nginx url 转发 修改访问路径
https://www.wekri.com/nginx/nginx-url-rewrite/