Configuration Modification nginx supports pathinfo

Source: Internet
Author: User

Thinkphp supports providing friendly URLs through pathinfo and URL rewrite. You only need to set 'url _ model' => 2 in the configuration file. In Apache, you only need to enable the mod_rewrite module for normal access, but pathinfo is not supported by nginx by default, so we need to modify the nginx. conf file.

I searched the internet for a lot of methods that didn't work. After studying for a day, I found that the following configuration can perfectly support 'url _ model' => 2.

location /project/ {    index  index.PHP;    if (!-e $request_filename) {        rewrite  ^/project/(.*)$  /project/index.PHP/$1  last;        break;    }}location ~ .+\.PHP($|/) {    set $script    $uri;    set $path_info  "/";     if ($uri ~ "^(.+\.PHP)(/.+)") {        set $script     $1;        set $path_info  $2;     }            fastcgi_pass 127.0.0.1:9000;   fastcgi_index  index.PHP?IF_REWRITE=1;    include /APMServ/nginx/conf/fastcgi_params;    fastcgi_param PATH_INFO $path_info;   fastcgi_param SCRIPT_FILENAME  $document_root/$script;    fastcgi_param SCRIPT_NAME $script;}

In this example, all requests under the project are forwarded to the index. PHP to process, that is, the single portal file of thinkphp. Then, the request for the PHP file is sent to FastCGI for processing, and the support for path_info is added.

After nginx is restarted, URLs such as http: // localhost/project/index/insert, http: // localhost/project/index. php/index/delete can be accessed correctly.

Note that there must be a space between the IF and the parentheses in the nginx configuration file. Otherwise, the unknown ctictive error will be reported.

 

The most important thing is that I copied the above.


The following shows how to create a new CONF file for my configuration, such as linlook. conf.

Content:

Location ~ . + \. Php ($ | /){

Set $ script $ URI;

Set $ path_info "/";

Fcinclude gi. conf

If ($ URI ~ "^ (. + \. Php) (/. + )"){

Set $ script $1;

Set $ path_info $2;

}

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php? If_rewrite = 1;

Include/www/wdlinux/nginx-0.8.54/CONF/fastcgi_params;

Fastcgi_param path_info $ path_info;

Fastcgi_param script_filename $ document_root/$ script;

Fastcgi_param script_name $ script;

}

Content:

Server {

Listen 80;

SERVER_NAME test.linlook.com;

Root/www/web/test;

Index index. php index. html index.htm;

 

Include linlook. conf

 

Location ~ . * \. (GIF | JPG | JPEG | PNG | BMP | SWF) $ {

Expires 30d;

}

 

Location ~ . * \. (JS | CSS )? $ {

Expires 12 h;

}

}

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.