nginx 反向代理URI重写
nginx 反向代理URI重写
如果proxy_pass的URL定向里包括URI,那么请求中匹配到location中URI的部分会被proxy_pass后面URL中的URI替换,eg:
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
请求http://example.com/name/test.html 会被代理到http://127.0.0.1/remote/test.html
如果proxy_pass的URL定向里不包括URI,那么请求中的URI会保持原样传送给后端server,eg:
location /name/ {
proxy_pass http://127.0.0.1;
}
请求http://example/name/test.html 会被代理到http://127.0.0.1/name/test.html
一些情况下,不能确定替换的URI
location里是正则表达式,这种情况下,proxy_pass里最好不要有URI
在proxy_pass前面用了rewrite,如下,这种情况下,proxy_pass是无效的,eg:
location /name/ {
rewrite /name/([^/]+) /users?name=$1 break;
proxy_pass http://127.0.0.1;
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: