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

nginx 下CI访问 404 问题

[复制链接]
发表于 2012-10-23 09:26:27 | 显示全部楼层 |阅读模式
在nginx环境下访问我的ci ,
只能这种格式:http://localhost/index.php?c=home&m=view
如果使用:http://localhost/index.php/home/view/ 就报404 错误
后来总结规律发现,只要http://localhost/index.php/  后面带/ 就会出现404,
也就是说http://localhost/index.php 这个地址可以访问,
而http://localhost/index.php/  就404
不知道是什么原因,请高手指点!!不胜感激!!

发表于 2013-3-21 18:26:41 | 显示全部楼层
NGINX 默认不支持 PATH_INFO 模式,需要修改NGINX配置 让NGINX 来解析 index.php/controller/f 这种模式 具体配置:

#CI
server {
        listen      80;
        server_name www.ci.com;
        index       index.php index.html index.htm;
        root        "/servers/apps/CI";
      location ~ \.php{
       fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
            ##########################################pathinfo 模式
            set $path_info "";
            set $real_script_name $fastcgi_script_name;
            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$"){
                 set $real_script_name $1;
                 set $path_info $2;
            }
            include fastcgi.conf;
            fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
            fastcgi_param SCRIPT_NAME $real_script_name;
            fastcgi_param PATH_INFO $path_info;
            ##########################################nginx支持pathinfo 模式的重点   

       }      
}
发表于 2012-11-28 18:02:14 | 显示全部楼层
楼主你的问题解决没?可否分享下解决方法,我也遇到同样的问题了
发表于 2012-10-23 09:30:18 | 显示全部楼层
因为你的nginx配置的是截取.php文件后缀的访问转发到PHP-CGI,而index.php和index.php/是不一样的。。
你在nginx里面写一句:
  1. if (!-e $request_filename) {
  2.       rewrite ^.*$ /index.php last;
  3.     }
复制代码
发表于 2016-12-1 14:03:44 | 显示全部楼层
要看看你的nginx是什么版本,如果是新版(如:1.10以上),在location / 里面加入这个:
        index  index.php;
        try_files $uri $uri/ /index.php?$uri&$args;

完整如下:

location / {
        root   /root/www;
        index  index.php;
        try_files $uri $uri/ /index.php?$uri&$args;
    }
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2012-10-23 09:57:25 | 显示全部楼层
首先谢谢 gaoomei {:soso_e181:}。
我遇到的具体问题是这样的,我本已经有个一非ci框架的网站,我想转到ci框架里面,在此期间不想影响现有网站的访问,
我在网站的根目录下重新建了一个目录web1
想在这个目录下使用CI框架开发,用这个网址访问:http://localhost/web1/index.php/
而之前的根目录已经做过转发,即:http://localhost/ 默认访问的是 http://localhost/html/index.html (html:静态文件生成的目录);
规则:rewrite ^/$   /html/index.shtml last;
请问如何写规则可以让我的子目录下的ci框架也可以正常访问,现在还是访问不是404了,但是都跳到首页了,不知道什么原因,劳驾{:soso_e181:}
 楼主| 发表于 2012-12-27 23:56:29 | 显示全部楼层
还没有解决呢,我也在等高人指点呢
发表于 2014-8-13 18:20:04 | 显示全部楼层
xy631606923 发表于 2013-3-21 18:26
NGINX 默认不支持 PATH_INFO 模式,需要修改NGINX配置 让NGINX 来解析 index.php/controller/f 这种模式 具 ...

能解释一下就更好了
发表于 2014-8-25 13:59:23 | 显示全部楼层
还没解决吗,真头疼,thinkphp就没这个烦恼
发表于 2015-8-7 09:02:16 | 显示全部楼层
nginx 会将 index.php/ 当作目录进行处理
发表于 2015-8-7 09:11:22 | 显示全部楼层
http://localhost/index.php/home/view/  nginx 会将 index.php当作一个目录进行处理 。 其实你访问的应该是根目录下的 index.php 目录下的home 目录下的 view 目录下的 index.php  文件 。 你可以新建在你的根目录下建一个index.php目录,再在下面建 home 目录 ,在home 目录下建 view 目录 ,view 目录下建 一个 one.html 文件 , 你访问 http://localhost/index.php/home/view/one.html  应该是可以成功的 。

本版积分规则