4

This question already has an answer here:

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?

marked as duplicate by Mark Henderson Dec 22 '13 at 11:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

$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;

  • 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 6 '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 6 '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
-1

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..

Not the answer you're looking for? Browse other questions tagged or ask your own question.