Using the mirror module

Francis Daly francis at daoine.org
Tue Aug 14 07:44:04 UTC 2018


On Thu, Aug 09, 2018 at 07:04:50PM -0400, jlangr wrote:

Hi there,

> We got this working to wrap up the day.

Good that you have something working for you.

> My ignorance of nginx meant that I
> was interpreting the example literally--I viewed the "/mirror" as the name
> for the internal route, but that actually becomes part of the URL the mirror
> location proxy forwards to.

It's actually a bit more subtle than that.

The argument to the "mirror" directive is the local url of the subrequest;
it should start with "/" or "@".

Then, in the matching location{}, if you choose to proxy_pass, then the
proxy_pass rules come in to play. And it is proxy_pass that decides what
request to make to the upstream server.

http://nginx.org/r/proxy_pass

>             mirror /;

That means that the subrequest will be exactly "/"...

>         location = / {

...which will be handled in this location...

>             set $upstream_endpoint http://1.2.3.4:3002;
>             proxy_pass $upstream_endpoint$request_uri;

...and the proxy_pass argument includes something after the host:port,
so that is what the request to upstream will be.

An alternative could have been to use a named location -- "mirror
@mirror;", with "location @mirror { proxy_pass http://1.2.3.4:3002; }"
-- which would avoid the need for some of the extra variables.


But, once you have something that works, there is no need to change it :-)

Cheers,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list