用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3610|回复: 2
收起左侧

[已解决] ci在nginx下一个问题,不得解

[复制链接]
发表于 2011-9-13 20:11:09 | 显示全部楼层 |阅读模式
本帖最后由 慢慢走 于 2011-9-13 20:16 编辑

我刚学CI,和nginx,现在有个网站程序移植到nginx下(原是apache的),我请教个nginx配置问题,重写规则都已经改了(网上搜了个通用的CI框架的配置,现在的问题是,程序中有个函数是后台的在线编辑模板文件,模板文件大部分是php后缀名的,因此把以后缀名为php的文件名传递给功能函数,现在传递失败,但是除了php结尾的都可以传递(比如css结尾的),而且在原有的Apache下一切正常,不得解,是新手,nginx下应该怎么配置?
  路径举例:域名/admin/edittemplate/~auction~buy.php  (404错误,在apache下正常)
                      域名/ admin/edittemplate/~~css~common.css  (正常,可以在线编辑)
  
希望回复,功能函数如下
function edittemplate($dir='')
    {
        clearpagecache();
        $this->db->cache_delete_all();
        $dir=str_replace('~','/',$dir);                               //把"~"转为"/"
        $datas['admin']=$this->_check_admin_login(1);
        $this->_check_admin_permission(__function__,$datas['admin']);
        $datas['config']=$this->config_model->get_config();
        $datas['display_dir']=$dir;
        if(is_file('application/views/'.$datas['config']['template'].'/'.$datas['display_dir']))  //判断文件是否存在
            $datas['display_dir']=dirname($datas['display_dir']);
        $datas['path']='application/views/'.$datas['config']['template'].'/'.$dir;           //路径赋值
        if(is_file($datas['path']))
        {
            $datas['dir']=dirname($datas['path']);
            $datas['contents']=file_get_contents($datas['path']);                         //获取内容
        }
        else
            $datas['dir']=$datas['path'];
        $datas['fileslist']=array();
        $temp=scandir($datas['dir']);
        foreach($temp as $tmp)
            if(!in_array($tmp,array('.','..','.svn')))
                $datas['fileslist'][]=$tmp;
        foreach($datas['fileslist'] as &$file)
        {
            if(is_dir($datas['dir'].'/'.$file))
                $file=array('name'=>$file,'type'=>'dir');
            elseif(in_array(strtolower(end(explode('.',$datas['dir'].'/'.$file))),array('png','gif','jpg','jpeg')))
                $file=array('name'=>$file,'type'=>'img');
            else
                $file=array('name'=>$file,'type'=>'file');
        }
        unset($file);
        if(is_file($datas['path']))
        {
            $datas['filename']=basename($datas['path']);
            $datas['contents']=file_get_contents($datas['path']);
        }
        if(isset($_POST['contents']))
        {
            $this->_check_admin_permission(__function__."_post",$datas['admin']);
            $contents=$_POST['contents'];
            file_put_contents('application/views/'.$datas['config']['template'].'/'.$dir,$contents);
            redirect('admin/edittemplate/'.str_replace('/','~',$dir));
        }
        $this->load->view('admin/template/edittemplate',$datas);
    }



 楼主| 发表于 2011-9-13 20:17:14 | 显示全部楼层
本帖最后由 慢慢走 于 2011-9-13 20:18 编辑

再贴个nginx的配置,这个配置其他都正常server {
                 listen       80;
                server_name www.domain.com;

               if ($host != 'www.domain.com' ) {
                       rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
               }

                index index.php;
                root  html;
       location /
                   {
                                index index.php;
                                if (!-e $request_filename) {
                                        rewrite ^/(.*)$ /index.php?$1 last;
#                                        break;
                                }
                        }
        location ~ \.php$
                        {
              fastcgi_param  SCRIPT_FILENAME  /index.php;
                     
                location ~ ^(.+\.php)(.*)$ {
               root       html;
               fastcgi_index   index.php;
               fastcgi_split_path_info ^(.+\.php)(.*)$;
               fastcgi_param   SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
               fastcgi_param   PATH_INFO               $fastcgi_path_info;
               fastcgi_param   PATH_TRANSLATED /usr/local/nginx/html$fastcgi_path_info;
               fastcgi_pass   127.0.0.1:9000;
               include fastcgi_params;
                        }
               
                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }
                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }
                access_log off;

    }


}
发表于 2012-2-28 14:47:37 | 显示全部楼层
慢慢走 发表于 2011-9-13 20:17
再贴个nginx的配置,这个配置其他都正常server {
                 listen       80;
                serv ...

这个改写正合我用。
我的改写不知道为什么传不了post组。。。。

本版积分规则