美文网首页
Nginx proxy_pass的用法

Nginx proxy_pass的用法

作者: 饱饱想要的灵感 | 来源:发表于2022-12-20 16:16 被阅读0次

在nginx中配置proxy_pass代理转发时

  • 如果在proxy_pass后面的url包含/,表示绝对根路径, 匹配到的location将被消除;

  • 如果在proxy_pass后面的url不包含/,表示相对路径,匹配到的location也计入最终路径。

例如访问 http://192.168.1.1/popo/index.html, 采用四种配置:

配置 说明 结果
location /popo/ { proxy_pass http://127.0.0.1/; } 包含/, 表示绝对根路径, /popo/将被消除 代理到URL:http://127.0.0.1/index.html
location /popo/ { proxy_pass http://127.0.0.1; } 比配置一最后少了一个 /, 表示相对路径, /popo/不会消除, 也计入最终路径 代理到URL:http://127.0.0.1/popo/index.html
location /popo/ { proxy_pass http://127.0.0.1/abc/; } 包含/, 表示绝对根路径,
/popo/将被消除 代理到URL:http://127.0.0.1/abc/index.html
location /popo/ { proxy_pass http://127.0.0.1/abc; } 虽然比配置三最后少了一个 /, 但是代理路径中包含/, 表示绝对根路径, /popo/将被消除 代理到URL:http://127.0.0.1/abcindex.htmlhttp://127.0.0.1/abcindex.html)

相关文章

网友评论

      本文标题:Nginx proxy_pass的用法

      本文链接:https://www.haomeiwen.com/subject/jifpqdtx.html