关于ThinkPHP在Nginx服务器下因PATH_INFO出错的解决方法

参考:https://www.linuxidc.com/Linux/2011-11/46871.htm

这是一个ningx设置的问题,和TP无关。TP默认使用PATH_INFO来做CURD,而nginx默认设置不处理PATH_INFO,查看nginx可以看到出错日志:
2010/01/09 22:05:36 [error] 13988#9380: *3 CreateFile() "E:\company\home\labs\php\thinkphp\server\nginx-0.8.31/..\..\src/Examples/Form/index.php/Index/insert" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "POST /Examples/Form/index.php/Index/insert HTTP/1.1", host: "localhost", referrer: "http://localhost/Examples/Form/"
说明nginx把PATH_INFO当成了目录文件的一部份,所以找不到该文件。

解决方法一:修改TP设置,不使用PATH_INFO

解决方法二:修改nginx设置,支持PATH_INFO

本人使用CoreServer集成包,就以此为例,www.linuxidc.com 修改nginx.conf和fastcgi-params


       location ~ \.php$ {
修改为
       location ~ \.php/?.*$ {


         fastcgi_param   SCRIPT_FILENAME   $document_root2$fastcgi_script_name;
修改为
         set $fastcgi_script_name2 $fastcgi_script_name;
         if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
            set $fastcgi_script_name2 $1;
            set $path_info $2;
         }
         fastcgi_param   PATH_INFO $path_info;

         fastcgi_param   SCRIPT_FILENAME   $document_root2$fastcgi_script_name2;


fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
修改为
fastcgi_param   SCRIPT_NAME        $fastcgi_script_name2linux

猜你喜欢

转载自www.cnblogs.com/iitrust/p/12332999.html