Recently, something went wrong when migrating one of the company's servers from Apache to Nginx, so I made a note.
The problem lies in the fact that the above website is developed based on the ThinkPHP framework and cannot be configured using the default method. After searching on Baidu online, I found that this problem is very common. The configuration of the general solution is as follows:
server {
...
If (!-e $request_filename) {
;
break;
}
location ~ .+.php($|/) {
....
set $script $uri;
set $path_info "/";
If ($uri ~ "^(.+.php)(/.*)") {
set $script $1;
set $path_info $2;
}
Fastcgi_param PATH_INFO $path_info;
Fastcgi_param SCRIPT_FILENAME /path/to/web-root$script;
Yesterday, while reading a book, I suddenly discovered that the fastcgi module comes with a command specifically designed to solve such problems. The command is fastcgi_split_path_info. This command will separate the URL according to the given regular expression, thereby extracting the script name and path. info information, using this command can avoid using if statements and make the configuration simpler. (The if statement in the server part can be replaced by try_files). The new configuration is as follows:
server {
...
try_files $uri /index.php$uri;
}
....
Fastcgi_split_path_info ^(.+.php)(/.*)$;
Fastcgi_param PATH_INFO $fastcgi_path_info;
Fastcgi_param SCRIPT_FILENAME /path/to/web-root$fastcgi_script_name;