以下是请求http://xxx/say/hello时的所有可能情况
location | proxy_pass | 请求地址 |
---|---|---|
/say | http://host/ | http://host//hello |
/say/ | http://host/ | http://host/hello |
/say | http://host | http://host/say/hello |
/say/ | http://host | http://host/say/hello |
/say | http://host/speak/ | http://host/speak//hello |
/say/ | http://host/speak/ | http://host/speak/hello |
/say | http://host/speak | http://host/speak/hello |
/say/ | http://host/speak | http://host/speakhello |
总结:
- 当proxy_pass为ip:port的形式时,proxy_pass末尾如果加"/",proxy_pass不拼接location的路径,从location中不匹配的部分开始拼接,若不加"/",proxy_pass会拼接location的路径
- 当proxy_pass为ip:port/xxx的形式时,不管proxy_pass末尾加没加"/",都不会拼接location的路径,而是从location中不匹配的部分开始拼接