FastCGI script parameters
Select a script before sending the request
For a small site, allow just the PHP entry point that is required. The selected location must establish the filename PHP can actually read. The query string is not part of a filesystem path. A request to /hello.php?name=Ada uses the file hello.php and carries name=Ada separately. On a shared host, Nginx and FPM must agree on the absolute path; in separate containers they can have different mount paths, requiring an explicit mapping.
location = /hello.php { try_files /hello.php =404; include params.conf; fastcgi_pass 127.0.0.1:19029; fastcgi_cache off;}The exact location accepts only /hello.php after Nginx URI processing. The try_files check prevents dispatch when the file is absent. The lab permits no generic PHP execution and rejects other paths except the explicit static assets prefix. PHP scripts are not stored in that assets directory.
Build an explicit request contract
fastcgi_param SCRIPT_FILENAME $document_root/hello.php;fastcgi_param SCRIPT_NAME /hello.php;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param REDIRECT_STATUS 200;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param REQUEST_URI $request_uri;SCRIPT_FILENAME chooses the script on FPM’s filesystem. SCRIPT_NAME describes the script’s URL identity. QUERY_STRING supplies query data. The method, content type and body length describe the incoming request. REDIRECT_STATUS is included for CGI compatibility. The request URI is useful when an application has its own router. For production, review all metadata required by the framework, including HTTPS and server identity. Do not copy an unrelated distribution include file without examining it.
SCRIPT_FILENAME=/home/lab/site/www/hello.phpSCRIPT_NAME=/hello.phpQUERY_STRING=name=AdaREQUEST_METHOD=GETREQUEST_URI=/hello.php?name=AdaLocal fastcgi_param declarations replace the inherited parameter list rather than merging one item into it. If an include already sets SCRIPT_FILENAME, do not append another conflicting definition. Inspect the actual include file, whether named fastcgi_params, fastcgi.conf or something else. Keep all required parameters at the location level together.
Index and front-controller behavior
location / { try_files $uri /index.php?$query_string;}location = /index.php { try_files /index.php =404; # Use a reviewed complete parameter set with SCRIPT_FILENAME # fixed to the absolute index.php path, then fastcgi_pass.}location ~* \.php(?:/|$) { return 404; }This is a routing illustration, not a complete deployable configuration. A framework may route /products/42 through one fixed index.php entry point, while existing public assets are served directly. The broader PHP rejection does not replace a carefully controlled public document root; keep configuration, uploads, private files and dependencies outside it. fastcgi_index can append an index name to the FastCGI script-name variable for a slash-ended URI; it does not by itself choose the HTTP location or prove the file exists. PATH_INFO is a separate suffix that some applications need. fastcgi_split_path_info separates the script portion and suffix using two captures; verify actual file existence and parameter values before enabling such routing. The lab intentionally supports no PATH_INFO.
Practice and next step
Predict the routing for /hello.php?name=Ada, /missing.php, /hello.php/extra and /assets/site.css. Explain why a request must never select an arbitrary uploaded script.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
FastCGI script parameters
Map explicit PHP routes to existing script files, pass request parameters, and separate front-controller routing from static content.
What chooses the script on FPM's filesystem?
What does try_files /hello.php =404 check?
What if fastcgi_param is declared at the child level?
What is PATH_INFO?
Why keep uploads outside the executable document root?