代理转发规则
如果proxy_pass使用了URI,当传送请求到后端服务器时,规范化以后的请求路径与配置中的路径的匹配部分将被替换为指令中定义的URI(对应下文第一种情况)。
如果proxy_pass没有使用URI,传送到后端服务器的请求URI一般客户端发起的原始URI(下文第二种情况)。
访问地址:http://localhost:8080/abc/dfg
1
location /abc/ {
proxy_pass http://127.0.0.1:8080/;
}
代理到:http://127.0.0.1:8080/dfg
2
location /abc{
proxy_pass http://127.0.0.1:8080;
}
代理到:http://127.0.0.1:8080/abc/dfg
3
location /abc/ {
proxy_pass http://127.0.0.1:8080/api/;
}
代理到:http://127.0.0.1:8080/api/dfg
4
location /abc/ {
proxy_pass http://127.0.0.1:8080/api;
}
代理到:http://127.0.0.1:8080/apidfg
5
location /abc {
proxy_pass http://127.0.0.1:8080/;
}
代理到:http://127.0.0.1:8080//dfg
6
location /proxy {
proxy_pass http://127.0.0.1:8080;
}
代理到:http://127.0.0.1:8080/abc/dfg
7
location /abc/dfg {
proxy_pass http://127.0.0.1:8080/mno/xyz;
}
代理到:http://127.0.0.1:8080/mno/xyz
其他的匹配规则,可以看看别的
另附nginx官方文档链接和阿里Tengine中文版链接
链接: https://blog.redis.com.cn/doc/standard/httpproxy.html
链接: http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_proxy_module.html#proxy_pass