Using the mirror module

Francis Daly francis at
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.

>             mirror /;

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

>         location = / {

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

>             set $upstream_endpoint;
>             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; }"
-- 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 :-)


Francis Daly        francis at

More information about the nginx mailing list