TP框架在nginx中的配置

TP框架配置中默认URL_MODEL=1,而Nginx默认是不支持PATHINFO的。如果我们只想跑起来tp框架,很简单,只需到更改TP配置,设置URL_MODEL=3(兼容模式)。但是如果要让Nginx支持ThinkPHP PATHINFO需要做如下配置:

1、设置ThinkPHP URL模式URL_MODEL=1; 

2、修改nginx配置文件(红色部分更改称相应的内容)
server
{
listen 80;
server_name www.myblog.com;
index index.php;
root /Users/just/git/myblog;

location / {
if (!-e $request_filename) {
rewrite  ^/(.*)$  /index.php/$1  last;
break;
 }
}

location ~ \.php {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  include fastcgi_params;
  set $real_script_name $fastcgi_script_name;
  if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
    set $real_script_name $1;
    set $path_info $2;
  }
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
  }
}

  

posted @ 2022-07-01 11:39  xiager  阅读(502)  评论(0编辑  收藏  举报