CodeIgniter在nginx下404 not found

CodeIgniter是一套轻量级php框架,最近在学习这套框架。

从官网上下载了3.0版本配置在服务器上测试,我的配置环境是centos+nginx+php+mysql。

我将CI配置到服务器后,发现默认控制器总是可以正常访问的,把默认控制器的指向改成其他控制器也都可以访问,但是用页面里的链接或者直接url里手动输入就会报404。

查阅资料后才知道CI在nginx下运行是要配置一下,我的配置如下

 server {
        listen       80;
        server_name  test;
        
        location / {
            index index.html index.php;root  
            /data/www/test;
        }   
        
         location ~ \.php($|/) {
            
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param    PATH_TRANSLATED    $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }   
        
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }  
        access_log  /usr/local/nginx/logs/test.platform.access.log;
        error_log  /usr/local/nginx/logs/test.platform.error.log;
    }

 如上修改server就可以正常运行了

需要注意的地方:

location ~ \.php($|/) {
 一开始我的配置为:
location ~ \.php$ {  所以一直没有搞成功,这个问题折腾了很久,特此说明一下。
参考地址:
http://www.chenyudong.com/archives/codeigniter-in-nginx-and-url-rewrite.html
http://haiker.iteye.com/blog/917413
http://blog.csdn.net/ei__nino/article/details/8599304
http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=11791
http://qing.tiyee.net/post/2012-11-18/40041056531 (好东西,值得学习)

转载于:https://my.oschina.net/u/1036767/blog/634415

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值