I'm trying to execute a PHP file on my server at the url /~nik/t.php
(actual file is at /home/nik/public_html/t.php
). Here's
what my PHP settings look like:
location ~ ^/~(.+?)(/.*)\.php$ {
alias /home/$1/public_html;
# What should this regex be?
fastcgi_split_path_info ^/~nik/(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
I keep getting a 404, and when I comment out the clause around return 404;
, I'm able to see the error:
Unable to open primary script: /home/nik/public_html/~nik/t.php (No such file or directory)
Can you see what's wrong with my configuration, or point me to some docs on how to do this? It's unfortunate that an advanced knowledge of regexes is a requirement to configure nginx.
In fact that's a very basic regex mistake you did there.
As your second capture group in the
fastcgi_split_path_info
directive is(/.*)
then the whole regular expression^/~nik/(.+?\.php)(/.*)$
won't match/~nik/t.php
as it's not followed by a slash. The question mark is also useless here while that's not the cause of the behaviour you see.The correct regex should be
^/~nik/(.+\.php)(.*)$