$fastcgi_script_name
The $fastcgi_script_name variable contains the script name being processed by the FastCGI server. — NGINX Core (HTTP)
Description
The $fastcgi_script_name variable is used in the NGINX configuration to retrieve the script name that is passed to the FastCGI server. This variable is primarily set when using the `fastcgi_pass` directive, which forwards requests to a FastCGI server. When an incoming request is processed, NGINX extracts the script part of the URI from the request and sets the value of this variable accordingly. It ensures that the FastCGI application receives the correct script path for processing, which is crucial for applications that rely on specific routing mechanisms, like PHP or Python applications running under FastCGI. In typical usage, $fastcgi_script_name will return a value such as `/index.php` or `/app/script.php`, reflecting the script that should be executed. If no script is found or if the request does not target a script, the variable may be empty. Therefore, this variable is not only important for routing to the correct script, but also plays a critical role in applications where file access is strictly controlled by URL structure.
Config Example
location / {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}Subsystem
httpCacheable
NoContexts
http, server, locationEnsure that the `fastcgi_param SCRIPT_FILENAME` is correctly set to include the document root and the script name, or the FastCGI server may not locate the file correctly.
Remember that if the request does not point to a specific script or if the script does not exist, $fastcgi_script_name may be empty, leading to unexpected errors.
When modifying the request URI, make sure the $fastcgi_script_name is updated accordingly to reflect those changes.