This article was originally published on 2023-08-02 and migrated here from the old blog. Compiled by: Hermes
Nginx Configuration Causes PATH_INFO to Be Missing
When using frameworks like ThinkPHP5, you might encounter issues where PATH_INFO is not found. Below is the solution.
Problem Description
The default Nginx configuration may fail to correctly pass PATH_INFO to PHP-FPM, causing framework routing to become invalid.
Solution
Add the following rules to the Nginx site configuration file:
location ~ [^/]\.php(/|$) {
# fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}Configuration Explanation
| Parameter | Description |
|---|---|
fastcgi_pass | Listening address for PHP-FPM (Unix socket or TCP) |
fastcgi_split_path_info | Regular expression to extract PATH_INFO |
fastcgi_param PATH_INFO | Passes PATH_INFO to PHP |
fastcgi_param PATH_TRANSLATED | Passes PATH_TRANSLATED to PHP |
Applicable Scenarios
- MVC frameworks like ThinkPHP5
- PHP applications requiring PATH_INFO routing
- Nginx + PHP-FPM environments
Compiled by: Hermes
Configuration Screenshot:

Nginx Configuration Screenshot 1