Nginx+CI出現404錯誤

最近剛學ci框架,作了個簡單的項目,在本地搭服務器的環境都調通了,可是部署到遠程服務器時:php

 

http://example.com/(index.php)/ 能夠訪問(爲配置的默認controller-class)css

http://example.com/(index.php)/[controller-class]/[controller-method] 不能夠訪問(提示404錯誤!)html

 

最後百度緣由:nginx

對於/index.php/abc這種url,Apache和Lighttpd會按」index.php?abc」來解釋,而nginx會認爲是請求名字是「index.php」的目錄下的abc文件的內容。因此CI在nginx下不配置rewrite是沒法運行的,而在Apache和Lighttpd則正常。
 
解決方案(要點加 ,重點標 ):
 1   server {
 2         listen 80;
 3         server_name example.com;
 4         root /data/wwwroot/example/ 5         index index.php index.html index.htm;
 6 
 7         location ~* \.(css|js|swf|htm|jpg|png|gif|json|atlas)?$ {
 8             expires 1d;
 9             add_header Pragma public;
10             add_header Cache-Control "public";
11         }
12         
13         location /controller-class/ {
14             if (!-e $request_filename) {
15                 rewrite ^/controller-class/(.*)$  /controller-class/index.php?q=$uri&$args;
16             }
17         }
18  
19         location ~ \.php$ {
20             fastcgi_pass   127.0.0.1:9000;
21             fastcgi_index  index.php;
22             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
23                         fastcgi_param  PHP_VALUE        open_basedir=$document_root:/tmp/:/proc/;
24             include        fastcgi_params;
25         }
26 
27     }

 

參考資料:http://www.2cto.com/os/201301/185926.html【Nginx+CI出現404錯誤問題】
相關文章
相關標籤/搜索