Understanding alias (used as rewrite)

Francis Daly francis at daoine.org
Wed Jun 24 15:42:38 UTC 2015


On Tue, Jun 23, 2015 at 11:44:33PM -0700, E.B. wrote:

Hi there,

> Thanks for your ongoing helps! I hope someone
> can advise further

you seem to keep referring to "alias used as rewrite". I do not know
what you mean by that.

Could you explain?

When you do, it may be that it becomes clear where your mental model of
what "alias" (or maybe "rewrite") does, breaks down.


"alias" is, as you noted, documented at http://nginx.org/r/alias. It is
used to identify a filename that should be used to handle the request.

In short: there are two relevant kinds of location: prefix and
regex. ("exact" is a special case of "prefix".)

In a prefix location, the starting part of the request that matches the
"location" value is replaced with the "alias" value, and what results
becomes $request_filename. (There is more to it than that, but that
should be enough for now.)

In a regex location, the entire request is replaced with the "alias"
value, and what results becomes $request_filename.

In your example configs, if you replace the "include" line with something
like

  return 200 "location #1: request $request_uri -> file $request_filename\n";

(change the #1 to something that will identify the location to you each
time), then you can use "curl" to make your various requests and see
the responses.

Does that show you how each configuration was used?

If $request_filename identifies a file that does exist, it will
probably be used; if it identifies a file that does not exist, there
will probably be an error. But it all depends on the configuration that
is not yet shown.

And "rewrite" does something different, documented at
http://nginx.org/r/rewrite; it involves uris, not filenames.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list