文档
【location】
Syntax: location [ = | ~ | ~* | ^~ ] uri { ... }
location @name { ... }
Default: —
Context: server, location
【proxy_pass】
Syntax: proxy_pass URL;
Default: —
Context: location, if in location, limit_excpt
proxy_pass
概括
proxy_pass
后面不带路径,就原封不动传给后端。proxy_pass
后面带路径,就去掉 Location 再传给后端。
ℹ 哪些 URL 包含路径?
http://host ❌
http://host:port ❌
http://host/ ✔
http://host:port/ ✔
http://host:port/api ✔
http://host:port/api/ ✔
情况
location:/
proxy_pass:http://localhost:8080
/ → /
/api → /api
location:/api
proxy_pass:http://localhost:8080
/api → /
/api/xx → /api/xx
/api-xx → /api-xx
location:/api/
proxy_pass:http://localhost:8080
/api/ → /api/
/api/xx → /api/xx
location:/
proxy_pass:http://localhost:8080/
/ → /
/api → /api
location:/api
proxy_pass:http://localhost:8080/
/api → /
/api/ → //
/api/xx → //xx
location:/api/
proxy_pass:http://localhost:8080/
/api/ → //
/api/xx → //xx
location:/api
proxy_pass:http://localhost:8080/v1
/api → /v1
/api/ → /v1/
/api/xx → /v1/xx
location:/api/
proxy_pass:http://localhost:8080/v1
/api/ → /v1
/api/xx → /v1xx
location:/api
proxy_pass:http://localhost:8080/v1/
/api → /v1/
/api/ → /v1//
/api/xx → /v1//xx
location:/api/
proxy_pass:http://localhost:8080/v1/
/api/ → /v1/
/api/xx → /v1/xx
参考
https://cloud.tencent.com/developer/article/2422272
https://cloud.tencent.com/developer/article/2421835
https://blog.csdn.net/q1298252589/article/details/120729989
https://blog.csdn.net/caidingnu/article/details/109448094