can't run php in aliased directory outside the root directory

Francis Daly francis at
Thu Feb 23 22:37:16 UTC 2012

On Thu, Feb 23, 2012 at 04:12:49PM -0500, caleboconnell wrote:

Hi there,

There is an issue with using php in an aliased location; but you don't
seem to use "alias" in your configuration at all, so that's not the
problem here.

> The actual path to the PHP fie we want to run is: 
> /var/www/media/courses/OCT-CIPPE/player.php.
> The path will always be /var/www/media/courses but the OCT-CIPPE will
> change based on the program we want to host.  The php file will always
> be titled player.php.
> Any help/suggestions as to how to change this so it will see the php
> file as a file it passes to php5-fpm.
>  ##  Web conference alias and flash video settings
>   location ^~ /media {

The "^~" there means that, if this is the most specific prefix-match
location, the regex locations are not checked.

>     root /var/www;
>   }
>   location ~ /media/courses/.*\.php$ {

And this one is a regex location. So this is not used at all. Which is
why your php script is served as-is, without fastcgi processing.

>From what you say above, this regex could be tightened to require
/player.php at the end. And maybe to require no / between courses/
and /player.php

>     root /var/www;
>     if ($fastcgi_script_name ~ /media/courses(/.*\.php)$) {
>      set $valid_fastcgi_script_name $1;
>     }

I'm not sure what that part tries to do; it's an "if" inside a "location",
so it probably does not do what you expect.

You don't seem to use $valid_fastcgi_script_name anyway.

I suspect that if you move the "location ~" block inside the "location
^~" block, you'll either see things Just Work, or at least see some more
useful error messages to point you at any other problems.

The "root" and "if" parts above are then probably ok to remove.

>     fastcgi_pass unix:/tmp/phpfpm.sock;
>     fastcgi_param SCRIPT_FILENAME  /var/www$fastcgi_script_name;
>     include fastcgi_params;

And the last two lines could become "include fastcgi.conf;", or
alternatively $document_root could be used instead of /var/www.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list