nginx配置使其支持pathinfo

in 折腾 with 0 comment

最近将一个PHP项目部署到php-fpm+nginx的线上后,出现了404、502错误,而在apache环境下就不会有错误,这是因为nginx配置语句中没有支持pathinfo。

支持pathinfo的正确配置语句如下:

location / {
     index  index.php;
     if (!-e $request_filename) { 
         rewrite  ^/(.*)$  /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 unix:/tmp/php-cgi.sock;
     fastcgi_index  index.php?IF_REWRITE=1;
     include fastcgi_params.conf;
     fastcgi_param PATH_INFO $path_info;
     fastcgi_param SCRIPT_FILENAME  $document_root/$script;
     fastcgi_param SCRIPT_NAME $script;
 }

如果出现「找不到fascgi_params.conf文件」的错误,则在nginx配置目录下找到fastcgi_params文件将其重命名为fastcgi_params.conf

Responses
选择表情选择表情