Nginx HTTP Proxying位置之间的链接

假设我有一个域test.com。 和Nginx服务几个应用程序。 我能怎么做:

  • test.com/match/here – 这将是请求

nginx处理为:

  • test.com/new/prefix/match/here

用nginx可以吗?

#server context location /match/here { proxy_pass http://example.com/new/prefix; } location /app { ... } . . . 

另一个问题是如何一个位置可以通过nginxconfiguration只能redirect到另一个位置?

先谢谢你!

为了使nginx进程请求从test.com/match/here位置到test.com/new/prefix/match/here ,您需要执行以下操作:

 location ~ /match/here(.*) { rewrite ^ /new/prefix/match/here$1 last; } 

当您想要将请求传递给处理请求的另一个程序时,使用proxy_pass 。 从你的问题看来,你只是想改变请求的URI,这是完成上述条目。

有关rewrite指令的更多信息,请查看http://nginx.org/en/docs/http/ngx_http_rewrite_module.html