Make Nginx support ThinkPHP framework_PHP tutorial

WBOY
Release: 2016-07-14 10:07:00
Original
831 people have browsed it

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;
}

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;

}

http://www.bkjia.com/PHPjc/477891.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477891.htmlTechArticleRecently, there was a problem when migrating one of the company's servers from Apache to Nginx, so I made a special notes. The problem is that the above website is developed based on the ThinkPHP framework, using default...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template