# FastCGI 在 stderr 中发送“主脚本未知”

- **ID:** `nginx/fastcgi-primary-script-unknown`
- **领域:** nginx
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 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 | — | — |

## 解决方案

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

## 无效尝试

- **** — The socket path must match the actual FastCGI server listener; the error is about script not found, not connection. (60% 失败率)
- **** — If the root is wrong, the script path will still be incorrect. (70% 失败率)
- **** — fastcgi_params does not set SCRIPT_FILENAME; you need fastcgi_index or explicit fastcgi_param. (80% 失败率)
