系统相关
首页 > 系统相关> > nginx 反向代理 uri 重写

nginx 反向代理 uri 重写

作者:互联网

参考: https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite

有个需求

http://myserver:80/foo/bar 反向代理到后台端 http://localhost:3200/bar

两种方法,第二种是最正确的

第一种

location  /foo {
  rewrite /foo/(.*) /$1  break;
  proxy_pass         http://localhost:3200;
  proxy_redirect     off;
  proxy_set_header   Host $host;
}

第二种

location /foo {
  proxy_pass http://localhost:3200/;
}

upstream后面是否带反斜线很重要,
请注意proxy_pass指令末尾的附加/。NGINX将去掉匹配的前缀/foo,并将剩余的前缀传递给后端服务器的/路径。
因此,http://myserver:80/foo/bar 将发布到后端http://localhost:3200/bar.

标签:http,3200,uri,nginx,proxy,bar,foo,重写,localhost
来源: https://www.cnblogs.com/faberbeta/p/15025752.html