I have this defining an alias (latest iteration of it):
location ~ /xxx/(.*).php($|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /xxx/web/blog/xxx/$1.php;
include fastcgi_params;
}
location ~ /xxx(.*) {
autoindex on;
alias /xxx/web/blog/xxx$1;
}
To try and define a wordpress install within the directory of xxx
of xxx.com
(for example).
Now when I take out the PHP path I get the index.php file downloaded to my computer but as soon as I add PHP fpm, as defined by the php location, I get:
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
In the logs. I have tried debug mode in error logs but it all looks good.
I do have a php location already doing:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri =404;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /xxx/web/live/backend/web/$fastcgi_script_name;
include fastcgi_params;
}
I have checked the output of /xxx/web/blog/xxx/$1.php
using return 200 "/xxx/web/blog/xxx/$1.php";
and it looks perfect.
I should add that I have been searhcing on SE for about 3 hours and not a single post on this actually solved my problems yet, including:
- https://stackoverflow.com/questions/8300022/nginx-serving-a-directory-as-an-alias
- https://stackoverflow.com/questions/21399789/nginx-how-to-create-an-alias-url-route
- Nginx 1 FastCGI sent in stderr: “Primary script unknown”
- best way to debug nginx config file?
So why won't this work?
Ok so I decided to go back to basics here and I drilled my code down to:
And I have no idea why but it works, I am fairly cetain I already tried something very close to this.
I thought it was because I added:
try_files $uri $uri/ /index.php?$args;
but then I removed that and it still worked.If someone can explain how aliases and PHP within them works a bit better and why it wouldn't work for me then I would accept that answer since that is effectively the question.