nginx+ci出现404错误

最近刚学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则正常。

解决方案(要点加粗,重点标红):

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 }
1213 location /controller-class/ {
14if (!-e $request_filename) {
15 rewrite ^/controller-class/(.*)$ /controller-class/index.php?q=$uri&$args;
16 }
17 }
1819 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/;
24include fastcgi_params;
25 }
2627 }

参考资料:http://www.2cto.com/os/201301/185926.html【nginx+ci出现404错误问题】

以上就介绍了nginx+ci出现404错误,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。

Posted in 未分类

发表评论