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

- **ID:** `nginx/fastcgi-primary-script-unknown`
- **Domain:** nginx
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 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 | — | — |

## Workarounds

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;`** (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;`
   ```
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;** (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;
   ```
3. **Check that the script file exists on the filesystem with correct permissions. Run: `ls -la /path/to/root/index.php`** (95% success)
   ```
   Check that the script file exists on the filesystem with correct permissions. Run: `ls -la /path/to/root/index.php`
   ```

## Dead Ends

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