Understanding alias (used as rewrite)

E.B. emailbuilder88 at yahoo.com
Wed Jun 24 06:44:33 UTC 2015

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

> >> You're probably looking for this
> >>
> >> fastcgi_param SCRIPT_FILENAME /another/different/path/anotehrscript.php;
> >
> > Excellent point! Thanks you!
> > However, what if the alias was NOT to a php file? Is using
> > rewrite the only solution - alias not able to working? What
> > is alias doing to cause 404?
> This config works for me.
>   location ~ ^/test {
>     alias /data/public_html/somefile.php;
>     include fastcgi.conf;
>     fastcgi_pass;
>   }

Yes, I had also got similar to work, but
only for the exact match uri-- the first
in my list of possible uris that must work:


I still get 404 for the last 3. That's why
I thinking it was adding the end of the original
uri to the alias redirect. but Im not sure.
(I used prefix match not regex match but I 
now tried your version with regex and get same

> Check what your error log says to find out why it returns 404.

Im not getting anything in my log I dont know
why (access log shows the requested uri but
I cant find the file not found error). I checked
php log too and basic nginx error log. I have a
access and error log set for this domain. Is
that where the file not found error should be going?

> Also the question mark you put will become part of file name php look
> for (it'll look for 'file.php?' instead of 'file.php'.

I was using the ? to try and avoid unknown file
lookups because I thought the part of the uri
after the matching location prefix was being
added to the aliased location.  I thought I could
pass it as a query string to PHP so I could ignore
it that way.

But you help clarify that it won't work that way
so I understand partly why I am getting 404, thank

Part of what is not clear is if/when alias will have
the rest of the uri after the match prefix added to
it??  The doc:


says nothing, but it begins to appear to me that if
you end the aliased location with / then it will have
the rest of the original uri added to it, but if you
don't end the alias with / then it will be taken without

If that's not right, can someone explain?

And if that is right, why isn't it documented (a
simply and imporant key feature should have that

More information about the nginx mailing list