访问url不变:http://192.168.1.1/proxy/test.html

1.location /proxy   proxy_pass http://127.0.0.1
  http://127.0.0.1/proxy/test.html
2.location /proxy   proxy_pass http://127.0.0.1/
  http://127.0.0.1//test.html


3.location /proxy/  proxy_pass http://127.0.0.1
  http://127.0.0.1/proxy/test.html
4.location /proxy/  proxy_pass http://127.0.0.1/
  http://127.0.0.1/test.html


5.location /proxy   proxy_pass http://127.0.0.1/abc
  http://127.0.0.1/abc/test.html
6.location /proxy   proxy_pass http://127.0.0.1/abc/
  http://127.0.0.1/abc//test.html


7.location /proxy/  proxy_pass http://127.0.0.1/abc
  http://127.0.0.1/abctest.html
8.location /proxy/  proxy_pass http://127.0.0.1/abc/
  http://127.0.0.1/abc/test.html

瞎总结一下:

1.第2和第6实际的url会出现双斜杠,所以location匹配的时候,建议在URI最后加上斜杆;

2.看了官方文档proxy_pass的例子,只看到示例第3和第8,即location的URI最后要有斜杠;proxy_pass如果有URI,最后也要有斜杠。

  其实location和proxy_pass的URI最后面有无斜杠都可以,只要遵循官方的规则即可;

  a.proxy_pass有URI,proxy_pass的URI与location替换;

  b.proxy_pass无URI,请求中的URI原封不动传递到后端server。

3.个人建议,location的URI以斜杠结尾,proxy_pass若指定了URI,URI最后面也要跟上斜杠。

相关文章:

  • 2021-10-06
  • 2022-12-23
  • 2021-05-19
  • 2021-07-21
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
猜你喜欢
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-03-22
相关资源
相似解决方案