Nginx configuration supports php pathinfo mode configuration

Source: Internet
Author: User
Nginx mode does not support pathinfo mode. a url similar to info. php/hello mode will be prompted that the page cannot be found. The following uses regular expressions

Nginx mode does not support pathinfo mode. a url similar to info. php/hello mode will be prompted that the page cannot be found. The following method uses regular expressions to find the actual file path and pathinfo, so that nginx supports pathinfo.

Location ~ \. Php $ {root html; fastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php; ## simulate pathinfoset $ path_info "" by setting; set $ real_script_name $ fastcgi_script_name; if ($ fastcgi_script_name ~ "^ (. +? \. Php )(/. +) $ ") {set $ real_script_name $1; set $ path_info $2;} your SCRIPT_FILENAME $ document_root $ real_script_name; your SCRIPT_NAME $ real_script_name; your PATH_INFO $ path_info; include fastcgi_params ;}

Key points:

1 .~ \. Php cannot be followed by $ to match all *. php/* URLs

2. change SCRIPT_FILENAME by setting

I actually used Zhang to integrate this code into fastcgi_params. The following is an example of my nginx configuration file:

The nginx code that supports pathinfo is as follows:

# In The nginx. conf server section:

server {listen       8080;server_name  localhost;location ~ \.php {include        fastcgi.conf;}}

# Key points: \. php is not followed by $ to match all *. php/* forms
# For the key code, see section at the beginning of fastcgi. conf.

The fastcgi. conf code is as follows:

Fastcgi_pass 127.0.0.1: 9000; # fastcgi_index index. php; set $ path_info ""; set $ real_script_name $ fastcgi_script_name; if ($ fastcgi_script_name ~ "^ (. +? \. Php )(/. +) $ ") {set $ real_script_name $1; set $ path_info $2;} using SCRIPT_FILENAME $ document_root $ real_script_name; fastcgi_param SCRIPT_NAME $ real_script_name; using PATH_INFO $ path_info; # The above is the key part that supports pathinfo: GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; descriquery_string $ QUERY_STRING; descrirequest_method $ REQUEST_METHOD; descricontent_type $ CONTENT_TYPE; descricontent_length $ CONTENT_LENGTH; # define SCRIPT_FILENAME $ document_root $ response; # define SCRIPT_NAME $ response; required REQUEST_URI $ request_uri; required DOCUMENT_URI $ document_uri; required DOCUMENT_ROOT $ document_root; required SERVER_PROTOCOL $ server_protocol; required REMOTE_ADDR $ response; fastcgi_param REMOTE_PORT $ remote_port; fastcgi_param SERVER_ADDR $ server_addr; fastcgi_param SERVER_PORT $ server_port; fastcgi_param SERVER_NAME $ server_name; # PHP only, required if PHP was built with -- enable-force-cgi-redirect # fastcgi_param REDIRECT_STATUS 200;

Your own configuration:

server{listen       80;server_name  www.touchopenid.com;index index.html index.htm index.php;root  /data0/htdocs/openid;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;include        fastcgi_params;fastcgi_param  PATH_INFO                $path_info;fastcgi_param  SCRIPT_FILENAME          $document_root$script;fastcgi_param  SCRIPT_NAME              $script;}
Related Article

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.