Configure the PathInfo mode in Nginx to support thinkphp URL rewriting _nginx

Source: Internet
Author: User

A recent project used thinkphp as a development framework, the URL we use the pathinfo mode, but nginx default is not supported PathInfo, need to be manually configured to do, We then followed the Nginx pathinfo support configuration According to the following methods:
Modify the nginx.conf, locate the location ~ php${} in the server, modify to location ~. php {}, and add the following:

Copy Code code as follows:

Set $path _info "";
Set $real _script_name $fastcgi _script_name;
if ($fastcgi _script_name ~ "^" ^ (. +?). PHP) (/.+) $ ") {
Set $real _script_name $;
Set $path _info $;
}
Fastcgi_param script_filename $document _root$real_script_name;
Fastcgi_param script_name $real _script_name;
Fastcgi_param path_info $path _info;

However, no matter how we test, we found that the PathInfo mode always does not run correctly, even after running, {: U} method is always error, print $_server found php_self is always wrong.
But still pathinfo can not work correctly, so we determine is thinkphp configuration problem, found that is actually thinkphp _php_file problem, in the entry file index.php add configuration define (' _php_file_ ', $_ server[' Script_name ']), problem solved.
If the $_server[' script_name ' path is also incorrect, replace it with the correct file path first.

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.