官方文檔 http://nginx.org/en/docs/http/ngx_http_core_module.html#location
location 末尾是否加 /
的區別
1. 末尾有’/’
location /proxy/ { #末尾有'/'
proxy_pass http://127.0.0.1:8080/;
}
匹配以 /proxy/
開頭的路徑。 eg: /proxy/aaa、/proxy/bbb、/proxy/aaa/bbb
- 訪問 localhost:80/proxy/aaa,代理到 127.0.0.1:8080/aaa
2. 末尾無’/’
location /proxy { #末尾無'/'
proxy_pass http://127.0.0.1:8080/;
}
匹配以 /proxy
開頭的路徑。 eg: /proxyaaa、/proxy/xxx/yyy、/proxy-xxx
- 訪問 localhost:80/proxyaaa,代理到 127.0.0.1:8080/aaa
- 訪問 localhost:80/proxy/aaa,代理到 127.0.0.1:8080//aaa (兩個 ‘//’)
end