問題
apache下正常運行的tp或者yii框架,遷移到nginx後無法訪問
解決方案
這裏主要針對兩部分進行解決
- 重新規則,主要原因是url界面美化後,無法識別url
#在location中加入重新的判斷,可以正常訪問
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php$1 last;
}
}
- 路由問題,我這裏TP3.2自定義的路由規則,會顯示錯誤
#這裏不僅要執行上面那一步,還要對location ~ \.php(.*)$ 中的判斷進行修改,主要針對url的
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
set $path_info "";
set $fastcgi_script_name_new $fastcgi_script_name;
if ($fastcgi_script_name ~* "^(.+\.php)(/.+)$" ) {
set $fastcgi_script_name_new $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name_new;
fastcgi_param SCRIPT_NAME $fastcgi_script_name_new;
fastcgi_param PATH_INFO $path_info;