MNMP nginx1.6 Support PathInfo configuration, support thinkphp URL format

Source: Internet
Author: User
Tags nginx server

There are several access formats for the Thinkphp framework project, where PathInfo is the default basic Access format: http://hostname:port/index.php/module name/action name/parameter 1/value of parameter 1/

PathInfo is actually a parameter, can be obtained through $_server[' Path_info ', thinkphp framework by parsing it to find the corresponding modules and methods.

Apache server is supported by default PathInfo, but Nginx server does not support this format, need to be configured, configured as follows:

Below is the Nginx configuration in the Mnmp under Mac

1. Locate the NGINGX configuration file nginx.conf

The location item in the server,

before the modification:
server {        listen       7888;        server_name  local.tpdemo.com;        Root/applications/mamp/htdocs/thinkphp_demo/;access_log          /applications/mamp/logs/nginx_tpdemo_access.log; Error_log            /applications/mamp/logs/nginx_tpdemo_error.log Debug;        Location/{            index  index.html index.htm index.php;location ~ \.php {try_files        $uri =404;fastcgi_pass     Unix:/applications/mamp/library/logs/fastcgi/nginxfastcgi.sock;fastcgi_param    Script_filename $document _root$fastcgi_script_name;include          Fastcgi_params;}}}    

  

Modified to:

server {Listen 7888;        server_name local.tpdemo.com; root/applications/mamp/htdocs/thinkphp_demo/;access_log/applications/mamp/logs/nginx_tpdemo_access.log;error_l        Og/applications/mamp/logs/nginx_tpdemo_error.log Debug; Location/{index index.html index.htm index.php;
               #重写隐藏掉index. PHP section #如果请求既不是一个文件, nor is it a directory, then execute the rewrite rule if (!-e $request _filename) {#地址作为将参数rewrite到index. php. Rewrite ^/(. *) $/index.php/$1; #若是子目录则使用下面这句, change the subdir to a directory name. #rewrite ^/subdir/(. *) $/subdir/index.php/$1; }Location ~ \.php {try_files $uri =404;fastcgi_pass unix:/applications/mamp/library/logs/fastcgi/nginxfastcgi.so Ck;fastcgi_param script_filename $document _root$fastcgi_script_name;include fastcgi_params;#定义变量 $path _info for storing pathinfo information set $path _info ""; #定义变量 $real _script_name for storing the real address set $real _script_name $fastcgi _script_name; #如果地址与引号内的正则表达式匹配 if ($fastcgi _script_name ~ "^ (. +?\.php) (/.+) $") {#将文件地址赋值给变量 $real _script _name set $real _script_name $; #将文件地址后的参数赋值给变量 $path _info set $path _info; } #配置fastcgi的一些参数 fastcgi_param script_name $real _script_name; Fastcgi_param path_info $path _info;} } }

  

  

2. Edit the php.ini file
Comment out configuration item cgi.fix_pathinfo (front Plus;)
3. Restart phpcgi and Nginx

MNMP nginx1.6 Support PathInfo configuration, support thinkphp URL format

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.