在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) |
网友评论