Nginx proxy_pass 后缀规则

proxy_pass 规则

Note that in the first example above, the address of the proxied server is followed by a URI, /link/. If the URI is specified along with the address, it replaces the part of the request URI that matches the location parameter. For example, here the request with the /some/path/page.html URI will be proxied to http://www.example.com/link/page.html. If the address is specified without a URI, or it is not possible to determine the part of URI to be replaced, the full request URI is passed (possibly, modified).

引自:https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

例如本地80端口Nginx代理8080端口服务,同样是访问 http://127.0.0.1/test/hello

配置1:

location /test/ {
    proxy_pass http://127.0.0.1:8080;
}

会访问被代理服务的: http://127.0.0.1:8080/test/hello

配置2:

location /test/ {
    proxy_pass http://127.0.0.1:8080/;
}

会访问被代理服务的: http://127.0.0.1:8080/hello

参考文档

发布了102 篇原创文章 · 获赞 600 · 访问量 127万+

猜你喜欢

转载自blog.csdn.net/xiao__gui/article/details/102712959