0

I want to work simple url like http://host/test.php, note there are no trailing / at the end.

I start from standard config from nginx site + serverfault:

 location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^((?U).+\.php)(.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; } 

end http://host/test.php/ works, but http://host/test.php without trailing / do not work.

I try to change to such config:

 location ~ \.php$ { fastcgi_split_path_info ^/(.+\.php)(.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; } 

and I got 404, and get from php-fpm

Primary script unknown

So have you idea how to make http://host/test.php works without trailing /? I tried many variants, but failed to understand what is wrong. I used nginx 1.8.1

Update

1) This problem only appears if I set chroot in /etc/php-fpm.d/www.conf

2) I find out using strace that for url with test.php/ php-fpm got SCRIPT_NAME/test.php\v\n and with url test.php I got SCRIPT_NAME/test.php\v\t. So first one end with '\n' and second one end with '\t' can not get why.

Update 2 Looks like a bug, I try 1.9.13 and the same config, not working with 1.8.1, works fine.

2 Answers 2

1

The first block works for me (with or without trailing slash), so there may be another conflicting location in your configuration which prevents one variant from working.

The second block is not capturing the leading '/' of the URI so the test if (!-f $document_root$fastcgi_script_name) always fails.

I presume that your php-fpm configuration must already know your document root, because it is usual to define SCRIPT_FILENAME as the full path:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
4
  • yes, php-fpm do chroot to value of $document_root. What version of nginx do you have? Commented Apr 6, 2016 at 12:56
  • @user1034749 I am testing on 1.8.0 Commented Apr 6, 2016 at 13:02
  • Looks like problem in php-frm, if remove chroot directive and add $document_root test.php works, if I enable chroot in php-fpm works only test.php/ Commented Apr 6, 2016 at 13:28
  • I update my question, if you can please take a look. Commented Apr 6, 2016 at 14:08
0

When using chroot for PHP-FPM, you have to define SCRIPT_FILENAME relative to the chroot environment. SCRIPT_FILENAME tells PHP-FPM where to find your script.

For example, if your web site index page is in /var/www/index.php, and your chroot is set to /var/www, the SCRIPT_FILENAME has to be /index.php instead of /var/www/index.php, which is the default nginx sets.

So, you have to insert the directory inside the chroot before $fastcgi_script_name in your configuration, so that PHP-FPM will find your script.

1
  • As you see I already done this, see line SCRIPT_FILENAME $fastcgi_script_name in my config, my chroot == $document_root, and php-fpm find file if I add / at the end, see again my question, so I configure in almost right way, the problem in \n vs \t, but I doubt that this is related to prefix of filename Commented Apr 6, 2016 at 17:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.