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

[HELP] 配置NGINX去除index.php失败

[复制链接]
发表于 2015-4-1 23:40:49 | 显示全部楼层 |阅读模式
我在部署到nginx之后带着index.php可以访问,但是去除index.php一直失败,求大神指点。这是我的配置:
location ~ \.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            root /usr/share/nginx/html;
            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_index index.php;
            include fastcgi_params;
        }

        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }


访问一直提示:File not found.
发表于 2015-4-1 23:42:35 | 显示全部楼层
nginx版本是多少,安装nginx时候是否选择了相应模块?
 楼主| 发表于 2015-4-1 23:56:24 | 显示全部楼层
nginx是1.6.2,你说的选择相应的模块指的是什么?
发表于 2015-4-2 00:49:40 | 显示全部楼层
兄弟,File not found. 应该是你的 FastCGI模块返回的php文件未找到。
错误:fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
这句话要改成:
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

详细内容请看:http://www.chenyudong.com/archives/codeigniter-in-nginx-and-url-rewrite.html
 楼主| 发表于 2015-4-2 22:08:27 | 显示全部楼层
本帖最后由 neuqliu 于 2015-4-2 22:09 编辑
z86823237 发表于 2015-4-2 00:49
兄弟,File not found. 应该是你的 FastCGI模块返回的php文件未找到。
错误:fastcgi_param SCRIPT_FILENAM ...

我试过那篇文章的做法,结果一样也是File not found,不知道还可能哪有问题呢,刚学PHP{:soso_e109:}
发表于 2015-4-3 09:42:22 | 显示全部楼层
location /     {           index index.php;           if (!-e $request_filename) {                rewrite ^/(.*)$ /index.php?$1 last;                break;           }     }
试试这个我也是找了好久才可以的

具体可以看http://www.cnblogs.com/whlives/p/4360617.html

发表于 2015-4-14 12:45:13 | 显示全部楼层
其实这个在nginx网站上已经提出了一个更好的解决方法 try_files,不用再rewrite了。
参考代码如下:
server {
  ......
  index index.php;
  location / {
    try_files $uri $uri/ /index.php;
    ......
  }
  ......
发表于 2015-4-20 17:29:38 | 显示全部楼层
我的配置是这样的,运行正常


server {
    listen   8081;
    server_name localhost;

    root  /Users/zhanghongwen/code/CodeIgniter;

    index index.php;
    try_files $uri $uri/ @rewrite;
    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {
        include fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /Users/zhanghongwen/code/CodeIgniter/$fastcgi_script_name;

    }
}
发表于 2016-6-21 15:09:42 | 显示全部楼层
使用楼上的方法成功了,看样子是rewrite 和 try files不知道有什么差别

本版积分规则