Debugging known - FastCGI sent to stderr: "Primary script unknown" while reading the response header from the upstream

There are many articles in SO that mention this error code:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream... 

This probably means that this error message is more or less useless.

The message states that the FastCGI handler does not like what was sent for some reason. The problem is that sometimes we don’t know what the reason is.

So, I am asking the question again: how to debug this error code?

Consider a situation where we have a very simple site, only with the phpinfo.php file. In addition, there is a very simple nginx configuration:

 server { server_name testsite.local; root /var/local/mysite/; location / { index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass fastcgi_backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } 

How can we see output / log exactly what fastcgi_params was sent to the script?

How can we see the actual error message? In my case, I am using php-fpm. He has no log information about this error. Logs do not add any lines for this error. Is there any verbose mode for php-fpm?

 /var/log/php-fpm/error.log /var/log/php-fpm/www-error.log 

I tried to install this in php-fpm.conf file

 log_level = notice 

and this is in the php-fpm.d / www.conf file:

 catch_workers_output = yes 
+7
php nginx
source share
1 answer

To answer your question:

  • in the php-fpm.d / www.conf file:

set the access.log entry:

 access.log = /var/log/$pool.access.log 
  1. restart the php-fpm service.

  2. try to access your page

  3. cat / var / log / www.access.log, you will see access logs, for example:

- - 10/Nov/2016:19:02:11 +0000 "GET /app.php" 404 - - 10/Nov/2016:19:02:37 +0000 "GET /app.php" 404

To fix the "Primary script unknown" problem:

  • if you see "GET /" without the correct php file name then this is your problem with nginx conf.

  • if you see "GET / app.php" with 404, it means that nginx correctly passes the script file name, but php-fpm could not access this file (user "php-fpm: php-fpm" does not have access to to your file, which delayed me for 3 hours)

Hope my answer helps.

+18
source share

All Articles