Nginx中proxy_pass的斜杠问题

在Nginx中配置proxy_pass时,需要注意斜杠的问题。

官方文档所述:

If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:

 location /name/ {
   proxy_pass http://127.0.0.1/remote/;
 }

If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:

  location /some/path/ {
    proxy_pass http://127.0.0.1;
  }

Before version 1.1.12, if proxy_pass is specified without a URI, the original request URI might be passed instead of the changed URI in some cases.

当proxy_pass后指定的是带斜杠的链接(其实就是URI,上例是一般情况,特别情况是http://127.0.0.1/ )时,请求的链接会被替换。如上例中,若请求的路由为/name/xxx,则下一站实际收到的请求路由为/remote/xxx;

当proxy_pass后指定的是不带斜杠的格式(即非URI),则不做任何替换,直接将原请求路由转发至下一站;

Contents


本站采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议

知识共享许可协议