nginx
runtime_error
ai_generated
true
FastCGI 在 stderr 中发送“主脚本未知”
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
ID: nginx/fastcgi-primary-script-unknown
90%修复率
87%置信度
1证据数
2024-07-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 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 | — | — | — |
根因分析
FastCGI 服务器找不到 SCRIPT_FILENAME 参数指定的脚本文件,通常是由于 root 或 try_files 配置错误。
English
The FastCGI server cannot find the script file specified by the SCRIPT_FILENAME parameter, often due to incorrect root or try_files configuration.
官方文档
https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_param解决方案
-
Ensure the root directive points to the correct document root and set SCRIPT_FILENAME explicitly: `fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;`
-
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;
-
Check that the script file exists on the filesystem with correct permissions. Run: `ls -la /path/to/root/index.php`
无效尝试
常见但无效的做法:
-
60% 失败
The socket path must match the actual FastCGI server listener; the error is about script not found, not connection.
-
70% 失败
If the root is wrong, the script path will still be incorrect.
-
80% 失败
fastcgi_params does not set SCRIPT_FILENAME; you need fastcgi_index or explicit fastcgi_param.