Understanding alias (used as rewrite)

E.B. emailbuilder88 at yahoo.com
Thu Jun 25 00:19:52 UTC 2015

First big appreciated to you and Edho
for helping!! Especially for things not
documented .  :)

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

Sure I wanted to take a prefix:


and make sure all uris that match
that prefix are served to the same

I got a rewrite to do that perfectly
but I see a lot of talk that rewrites
are what you used in apache and are
slow and not the nginx way of thinking.
and it make sense that because the
target file is fixed that avoiding
the rewrite engine will be faster just
pointing to a static aliased file.

I digress but hearing your opinion on
this is interesting to me.

> "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.

Im still wondering why the critical part
you kindly explaining below is not documented.
Isn't this basic feature and important info
to know?

> 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.

thanks. might have been causing less trouble
to the mailing list if this was known from the
docs.  :)

> In your example configs, if you replace the "include" line with something
> like
>   return 200 "location #1: request $request_uri -> file $request_filename\n";

this was so helpful it is amazing! removing 
all guessworkd! this should be included in
the docs too! i am very thankful to you for this!

> (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?

i discovered in the fastcgi conf file there
was a:
try_files $uri =404

so it overrided the alias and causeding
the problem. i guess this was a security
measure to prevent sneaking around the
filesystem for php requests. is there a
better way to effect same protection?
try_files $request_filename =404????

More information about the nginx mailing list