5

In PHP FastCGI Example & Pitfalls and Common Mistakes it is said that it should be:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

But in my Ubuntu (/etc/nginx/fastcgi_params), the setting is:

fastcgi_param   SCRIPT_FILENAME     $request_filename;

I am using the Ubuntu setting and didn't have any issue. What are the pitfalls?

techraf
  • 4,163
  • 8
  • 27
  • 44
Ryan
  • 5,341
  • 21
  • 71
  • 87

2 Answers2

6

$request_filename is just a nicer way of writing it.

$request_filename

This variable is equal to path to the file for the current request, formed from directives root or alias and URI request;

ceejayoz
  • 32,469
  • 7
  • 81
  • 105
  • 1
    I think you only need to split it into separate parts if your backend is running in a chroot in which case the request_filename would appear to be not valid to the backend. – Danack May 06 '13 at 12:00
  • @Danack I've also seen people store their scripts out of the document root and specify something like `/path/to/php/scripts/$fastcgi_script_name`. – ceejayoz May 06 '13 at 13:43
  • please, so the params passed in fastcgi_param are finally te process handle by the fastcgi params ? – Webwoman Sep 19 '18 at 17:00
  • Link in answer is broken. Kind of. It points to a blank wordpress site. – rudolfbyker Jun 11 '20 at 15:26
  • 1
    @rudolfbyker I've updated it; all the relevant info is cited as text in the answer for that sort of scenario. – ceejayoz Jun 11 '20 at 15:31
0

Basically you are not getting any errors when it comes to SCRIPT_FILENAME because it's already defined when you defined your root directive in your vhost file. So unless you defined it explicitly in your vhost file using fastcgi_param the value of SCRIPT_FILENAME would be taken from the root directive.. But ONE IMPORTANT POINT HERE. There is another variable that nginx needs in order to send the requests to the php server which is $fastcgi_script_name and you have to define it well in order to avoid repetitive URLs and errors with uri's that end with slash.

Conclusion:

To make everything work super nice, everyone should define SCRIPT_FILENAME explicitly either in 'fastcgi_params' file located in /etc/nginx folder or easily in the vhost of your site located in sites-available folder by including the following line in the php location block:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

or included in the 'fastcgi_params' file as you wrote above, either way it's the same..

But at the end BE CAREFUL, configurations differ for each CMS.. So search for in nginx for the best configuration for your current situation..

I hope it would help anyone in the future 'cuz it took me a lot of time to figure it out..

Dr.SMS
  • 61
  • 8