官方文档 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