Proxy Pass based on the first field in the URI

Francis Daly francis at daoine.org
Wed Sep 11 15:46:22 UTC 2019


On Wed, Sep 11, 2019 at 04:45:21PM +0200, meir hazon wrote:

Hi there,

> I would also like to pass the message to the proxy without the first part
> of the URI but use the rest of it.

http://nginx.org/r/proxy_pass

includes the section:

"""
If the proxy_pass directive is specified with a URI, then when a request
is passed to the server, the part of a normalized request URI matching
the location is replaced by a URI specified in the directive:
  location /name/ {
      proxy_pass http://127.0.0.1/remote/;
  }
"""

With that sample config, you want two "location"s:

> https://yyy.com/bla/aa/er
> if $1 == bla proxy pass to http://xxx.com/aa/er
> if $1 == vv proxy pass to http://ccc.com/aa/er

"/name/" == "/bla/"; "/remote/" == "/".
"/name/" == "/vv/"; "/remote/" == "/".

Does that work for you?

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list