$fastcgi_path_info
The variable $fastcgi_path_info contains the extra path information that follows the script name in a FastCGI request. — NGINX Core (HTTP)
Description
The $fastcgi_path_info variable is used in NGINX when interfacing with FastCGI applications. It provides the additional path information that may be included after the script name in the URL. This value is particularly important when working with RESTful APIs or web applications that require passing elements of the URL to the backend application for processing. For instance, if a request is made to /api/users/123, the '123' would be considered the path info, which would be returned as the value of the $fastcgi_path_info variable. This variable is primarily set when the FastCGI configuration is being utilized in the NGINX server block, specifically when handling script requests. It allows NGINX to correctly map the incoming requests to the corresponding FastCGI application, enabling more flexible routing and integration with various web frameworks which might rely on parsing that path info for their operations. It's important to note that if the URL does not contain any additional path segments after the script name, $fastcgi_path_info will be empty. In a typical scenario, when defining a FastCGI location block within NGINX, you will set the path to the FastCGI script while also allowing NGINX to manage the additional path information via this variable, which can be utilized by the depicted web applications accordingly.
Config Example
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}Subsystem
httpCacheable
NoContexts
http, server, location, ifMake sure to define PATH_INFO in your fastcgi_param settings to ensure NGINX passes it correctly to the backend.
Neglecting to set SCRIPT_FILENAME can result in errors, as paths need to be fully resolved for FastCGI scripts.
Not all FastCGI applications handle the path information correctly, so you should test your application to ensure it behaves as expected.