1.找到CI库的配置文件修改

$config['base_url']    = 'http://test.example.com';

$config['uri_protocol'] = 'PATH_INFO';

2.找到NGINX配置.在SERVER段中添加如下代码段

location /index.php{

                              fastcgi_pass  unix:/tmp/php-cgi.sock;

                              fastcgi_param SCRIPT_FILENAME /home/wwwroot/index.php;

                              fastcgi_param PATH_INFO $fastcgi_path_info;

                              fastcgi_split_path_info ^(.+\.php)(.*)$;

                              fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

                              include fcgi.conf;

            }

3.如果要做跳转的话,(比如:http://test.example.com/index.php/test,跳转

http://test.example.com/test.)可以server 段中添加如下配置

location /{

                  if (-f $request_filename) {

                              expires max;

                              break;

                      }

                      if (!-e $request_filename) {

                              rewrite ^/(.*)$ /index.php/$1 last;

                      }

  }

*****************************************************************************

前一段时间为了 PATH_INFO 问题搞得郁闷,来回忆下原来的配置(以CodeIgniter框架的配置为例):

server {
listen 80;
server_name test.local; location / {
root /www/test;
index index.html index.htm index.php;
rewrite ^/$ /index.php last;
rewrite ^/(?!index\.php|robots\.txt|images|js|styles)(.*)$ /index.php/$1 last;
} location ~ \.php($|/) {
root /www/test; set $script $uri;
set $path_info ""; if ($uri ~ "^(.+?\.php)(/.*)$") {
set $script $1;
set $path_info $2;
} fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_pass unix:/tmp/php-fpm.sock;
include fastcgi_params;
}
}

虽然可以实现 PATH_INFO 了,但是还是有缺陷,URL 中的中文不会被 urldecode。

好在,0.7.31 版本以上的 Nginx 新增了fastcgi_split_path_info 这个指令,现在配置起来清晰多了:

server {
listen 80;
server_name test.local; location / {
root /www/test;
index index.html index.htm index.php;
rewrite ^/$ /index.php last;
rewrite ^/(?!index\.php|robots\.txt|images|js|styles)(.*)$ /index.php/$1 last;
} location ~ ^(.+\.php)(.*)$ {
root /www/test; fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass unix:/tmp/php-fpm.sock;
include fastcgi_params;
}
}

指令的具体帮助请参考官方WIKI:

http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_split_path_info

– EOF –

Nginx支持PHP的CI框架的更多相关文章

  1. centos nginx环境下删除CI框架Index.php入口遇到404问题

    今天在网上百度看了很多文章,想要去掉index.php入口文件有好多方法,自己也照着在网站到根目录下新建了一个.htaccess文件,内容如下: RewriteEngine On RewriteCon ...

  2. Nginx 支持 CI 框架的配置并禁止使用 ip 访问

    #CIserver {        listen      80;        server_name www.ci.com;        index       index.php index ...

  3. 在nginx下去掉ci框架url中的index.php

    ci框架默认的url规则中带有应用的入口文件,例如: example.com/index.php/news/article/my_article 在以上URL中带有入口文件index.PHP,这样的U ...

  4. nginx location匹配顺序及CI框架的nginx配置

    Nginx location匹配顺序如下: 用前缀字符串定义的location规则对URI进行匹配测试. =号定义了精确的前缀字符串匹配,如果发现精确匹配则使用当前规则.否则继续下一步匹配. 匹配其它 ...

  5. Nginx配置CI框架问题(Linux平台下Centos系统)

    CI框架:官方文档 http://codeigniter.org.cn/user_guide/index.html CI框架的数据流程图如下: 其中:index.php作为入口文件,在安装好CI框架后 ...

  6. 配置nginx支持TP框架

    TP框架配置中默认URL_MODEL=1,而Nginx默认是不支持PATHINFO的.如果我们只想跑起来tp框架,很简单,只需到更改TP配置,设置URL_MODEL=3(兼容模式).但是如果要让Ngi ...

  7. 如何让nginx支持ThinkPHP框架(重点参考)

    公司有一款即将上线的应用服务端是基于ThinkPHP写的,本地测试无异常,上传到外网服务器后无法连接.这可把我和我的小伙伴们吓死了,怎么回事儿,本地测试都是对的呀! 我和我的小伙伴们开始找原因,换了一 ...

  8. ngnix 配置CI框架 与 CI的简单使用

    ngnix 支持 CI框架1.修改config.php 参考网址:https://www.chenyudong.com/archives/codeigniter-in-nginx-and-url-re ...

  9. CI框架源码阅读笔记3 全局函数Common.php

    从本篇开始,将深入CI框架的内部,一步步去探索这个框架的实现.结构和设计. Common.php文件定义了一系列的全局函数(一般来说,全局函数具有最高的加载优先权,因此大多数的框架中BootStrap ...

随机推荐

  1. canvas实现平铺

    代码: /** * Created by Administrator on 2016/1/30. */ function draw(id){ var canvas = document.getElem ...

  2. sql中in和exist语句的区别?(补充了left join和right join)

    in和exists(摘录自百度)in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询. 如果两个表中一个较小,一个是大表,则子查询表大的用exi ...

  3. 测试RDP回放

    Dim fso,num,flagflag=trueset bag=getobject("winmgmts:\\.\root\cimv2") Set fso=CreateObject ...

  4. linux 防暴力破解

    #!/bin/bash SCANIP=`grep "Failed" /var/log/secure* | awk '{print $(NF-3)}'| sort |uniq -c ...

  5. Activity--弹出底部窗口

    第一步 : 退出时候的布局文件exit_dialog_from_settings.xml <?xml version="1.0" encoding="UTF-8&q ...

  6. [poj1737]Connected Graph(连通图计数)

    题意:输出题中带有$n$个标号的图中连通图的个数. 解题关键: 令$f(n)$为连通图的个数,$g(n)$为非联通图的个数,$h(n)$为总的个数. 则$f(n) + g(n) = h(n)$ 考虑标 ...

  7. rlwrap:让控制台程序使用input.rc里的设置

    习惯了vi模式,在bash里配置input.rc可以使平时命令行操作都使用vi习惯,翻页和跳动光标都很方便 但是当运行一些交互式程序时,比如redis-cli,lua等,它们却不按input.rc的配 ...

  8. miRNA

    MicroRNA (miRNA)  是一类内生的.长度约为20-24个核苷酸的小 RNA,其在细胞内具有多种重要的调节作用.每个 miRNA 可以有多个靶基因的表达,而几个 miRNA 也可以调节同一 ...

  9. p2320&bzoj1192 鬼谷子的钱袋

    传送门(洛谷) 传送门(bzoj) 题目 鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向他咨询时政.有一天,他在咸阳游历的时候,朋友告诉他在咸阳最大的拍卖行(聚宝商行)将要举行一 ...

  10. p2071 座位安排

    传送门 题目 已知车上有N排座位,有N*2个人参加省赛,每排座位只能坐两人,且每个人都有自己想坐的排数,问最多使多少人坐到自己想坐的位置. 输入格式: 第一行,一个正整数N. 第二行至第N*2+1行, ...