nginx runtime_error ai_generated true

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

ID: nginx/fastcgi-primary-script-unknown

Also available as: JSON · Markdown · 中文
90%Fix Rate
87%Confidence
1Evidence
2024-07-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx 1.24.0 active
nginx 1.22.1 active
nginx 1.20.2 active
PHP-FPM 8.2 active
PHP-FPM 8.1 active

Root Cause

The FastCGI server cannot find the script file specified by the SCRIPT_FILENAME parameter, often due to incorrect root or try_files configuration.

generic

中文

FastCGI 服务器找不到 SCRIPT_FILENAME 参数指定的脚本文件,通常是由于 root 或 try_files 配置错误。

Official Documentation

https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_param

Workarounds

  1. 90% success Ensure the root directive points to the correct document root and set SCRIPT_FILENAME explicitly: `fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;`
    Ensure the root directive points to the correct document root and set SCRIPT_FILENAME explicitly: `fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;`
  2. 85% success Use try_files to pass the request to the front controller: `try_files $uri $uri/ /index.php?$query_string;` and then set fastcgi_index index.php;
    Use try_files to pass the request to the front controller: `try_files $uri $uri/ /index.php?$query_string;` and then set fastcgi_index index.php;
  3. 95% success Check that the script file exists on the filesystem with correct permissions. Run: `ls -la /path/to/root/index.php`
    Check that the script file exists on the filesystem with correct permissions. Run: `ls -la /path/to/root/index.php`

中文步骤

  1. Ensure the root directive points to the correct document root and set SCRIPT_FILENAME explicitly: `fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;`
  2. Use try_files to pass the request to the front controller: `try_files $uri $uri/ /index.php?$query_string;` and then set fastcgi_index index.php;
  3. Check that the script file exists on the filesystem with correct permissions. Run: `ls -la /path/to/root/index.php`

Dead Ends

Common approaches that don't work:

  1. 60% fail

    The socket path must match the actual FastCGI server listener; the error is about script not found, not connection.

  2. 70% fail

    If the root is wrong, the script path will still be incorrect.

  3. 80% fail

    fastcgi_params does not set SCRIPT_FILENAME; you need fastcgi_index or explicit fastcgi_param.