php not working from aliased subdir

Francis Daly francis at
Tue Jan 19 20:58:14 UTC 2016

On Tue, Jan 19, 2016 at 11:21:46AM +0200, Nikolaos Milas wrote:

Hi there,

>     location ~ /newlocation/(.*)\.php$ {
>         alias /var/websites/externaldir$1.php;
>         fastcgi_cache off;
>         try_files $uri =404;
>         include /etc/nginx/fastcgi_params;


> This config however always leads to "404 Not Found" errors for php files.
> What am I doing wrong?

add "debug_connection;" to your events{} section, then do
"curl -v", and then read the error
log that was generated.

You should see, among other lines, something like

http request line: "GET /newlocation/X.php HTTP/1.1"
http uri: "/newlocation/X.php"
test location: ~ "/newlocation/(.*)\.php$"
using configuration "/newlocation/(.*)\.php$"
try files phase: 11
trying to use file: "/newlocation/X.php" "/var/websites/externaldirX.php/newlocation/X.php"
http special response: 404, "/newlocation/X.php?"

Two things there: "alias" and "try_files" is not a good combination;
and your config loses the "/" that should be between "externaldir" and

If you temporarily remove the try_files line that is blocking you, and
repeat the "curl" command, then you will see what is sent to the fastcgi
server. Usually, the most interesting parameter is SCRIPT_FILENAME.

What value do you see for that? Is it exactly the filename that you want
your fastcgi server to process?

If not, what file do you want your fastcgi server to process?

After that, you can decide whether you want to use a try_files directive
in this location{} block, and if so, what exactly you want there.

(I tested this using a nginx/1.9.1, because that's what I had
handy. Different versions may show different output.)

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list