網(wǎng)上搜了很多方法都不奏效,研究了一天,發(fā)現(xiàn)通過以下的配置可以完美支持 'URL_MODEL' => 2 的情況了
復(fù)制代碼代碼如下:
location /project/ {
index index.php;
if (!-e $request_filename) {
rewrite ^/project/(.*)$ /project/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 127.0.0.1:9000;
fastcgi_index index.php?IF_REWRITE=1;
include /APMServ/nginx/conf/fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
}
這里先把project下的請求都轉(zhuǎn)發(fā)到index.php來處理,亦即ThinkPHP的單一入口文件;然后把對php文件的請求交給fastcgi來處理,并且添加對PATH_INFO的支持。
重啟Nginx以后,http://localhost/project/Index/insert, http://localhost/project/index.php/Index/delete 這樣的URL都可以正確訪問了。
還有一個地方需要注意的是,Nginx配置文件里 if 和后面的括號之間要有一個空格,不然會報unknown directive錯誤。