Enable Nginx to support the ThinkPHP framework

Source: Internet
Author: User

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;

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.