Recently, a problem occurred while migrating a company's server from Apache to Nginx. Let's take a note.
The problem is that the above website was developed based on the ThinkPHP framework and cannot be configured using the default method. This problem was found to be common after the Internet baidu. The general solution configuration is as follows:
Server {
...
If (! -E $ request_filename ){
Rewrite ^/(. *) $/index. php/$1 last;
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;
}
When I was reading a book yesterday, I suddenly found that the fastcgi module had a command specifically designed to solve this problem. The command is fastcgi_split_path_info, which separates URLs Based on the given regular expression, in this way, the Script Name and path info information are extracted. Using this command can avoid using the if statement, making the configuration easier. (The if Statement of server can be replaced by try_files.) The new configuration is as follows:
Server {
...
Try_files $ uri/index. php $ uri;
}
Location ~ . + \. Php ($ | /){
....
Fastcgi_split_path_info ^ (. + \. php) (/. *) $;
Fastcgi_param PATH_INFO $ fastcgi_path_info;
Fastcgi_param SCRIPT_FILENAME/path/to/web-root $ fastcgi_script_name;
}