最近剛學ci框架,做了個簡單的項目,在本地搭服務器的環境都調通了,但是部署到遠程服務器時:
http://example.com/(index.php)/ 可以訪問(為配置的默認controller-class)
http://example.com/(index.php)/[controller-class]/[controller-method] 不可以訪問(提示404錯誤!)
最后百度原因:
對于/index.php/abc這種url,Apache和Lighttpd會按”index.php?abc”來解釋,而nginx會認為是請求名字是“index.php”的目錄下的abc文件的內容。所以CI在nginx下不配置rewrite是無法運行的,而在Apache和Lighttpd則正常。
解決方案(要點加粗,重點標紅):
server {
listen ;
server_name example.com;
root /data/wwwroot/example/ index index.php index.html index.htm;
location ~* \.(css|js|swf|htm|jpg|png|gif|json|atlas)?$ {
expires d;
add_header Pragma public;
add_header Cache-Control "public";
}
location /controller-class/ {
if (!-e $request_filename) {
rewrite ^/controller-class/(.*)$ /controller-class/index.php?q=$uri&$args;
}
}
location ~ \.php$ {
fastcgi_pass ...:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE open_basedir=$document_root:/tmp/:/proc/;
include fastcgi_params;
}
}
以上內容是小編給大家分享的Nginx+CI出現404錯誤怎么解決的相關內容,希望對大家有所幫助!