Nginx+CI出现404错误

最近刚学ci框架,做了个简单的项目,在本地搭服务器的环境都调通了,但是部署到远程服务器时:

 

http://example.com/(index.php)/ 可以访问(为配置的默认controller-class www.xianbd.com)

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则正常。
 
解决方案(要点加 ,重点标 ):
复制代码
 1   server {
 2         listen 80;http://www.xianbd.com/
 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         }//  www.xianbd.com
12         
13         location /controller-class/ {
14             if (!-e $request_filename) {
15                 rewrite ^/controller-class/(.*)$  /controller-class/index.php?q=$uri&$args;
16             }
17         }//  www.xianbd.com
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错误问题 http://www.xianbd.com/】
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值