p_string

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  37 随笔 :: 0 文章 :: 1 评论 :: 71327 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

CI框架:官方文档 http://codeigniter.org.cn/user_guide/index.html

CI框架的数据流程图如下:

其中:index.php作为入口文件,在安装好CI框架后,index.php文件一般放置在Nginx服务器(其他服务器相同)所配置的web根目录下,Nginx配置文件在 xxx/nginx/conf/nginx.conf文件中,其中xxx为安装路径,如配置.php的解析文件可用如下模板:

 

复制代码
 1 server {
 2         listen       80;  // 监听的端口
 3         root /dir_1/dir_2/dir_3; 
 4         server_name www.example.com;
 5         index index.html index.htm index.php;
 6 
 7         location /
 8         {
 9             try_files $uri $uri/ /index.php?$args;
10         }
11         location ~ \.php$
12         {
13             fastcgi_pass 127.0.0.1:9000;
14             fastcgi_index index.php;
15             include fastcgi.conf;
16         }
17 }
复制代码

其中index.php文件要放置在根目录 /dir_1/dir_2/dir_3 下。URL为www.example.com:port/index.php/class/function/arg或者www.example.com/class/function/arg,其中www.example.com可换成ip地址加端口号,Nginx默认监听端口号为80,所以当端口为80时可不加,其他端口要在URL中明确指明

————————————————————————————————————————————————————————

而当有多个CI框架项目都需要布置在Nginx服务器是时,有两种方法:

1. 在Nginx配置文件中再配置一个虚拟机,并重新设置根目录,监听尚未使用的端口号(不推荐)

2. 不需要更改根目录,需要使用rewrite 指令和修改CI框架中的路由规则,即$route数组,具体如下:

例如当index文件所在位置为 /dir_1/dir_2/dir_3/test1/test2/test3/index.php

首先:将Nginx配置文件改为:

复制代码
server {
          listen       80;  // 监听的端口
          root /dir_1/dir_2/dir_3; 
          server_name www.example.com;
          index index.html index.htm index.php;
  
          location /
          {
              try_files $uri $uri/ /index.php?$args;
          }
          location ~ \.php$
          {
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_index index.php;
              include fastcgi.conf;
          }
          location /test1/test2/test3/
         {
             rewrite ^/test1/test2/test3/(.*)$ /test1/test2/test3/index.php/$1 break;
             fastcgi_index index.php;
             fastcgi_pass  127.0.0.1:9000;
             include fastcgi.conf;    // fastcgi.conf为php解析库相关文
     }
 }
复制代码

其中fastcgi.conf为自己定义的,如若无,可换成:

1 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
2 include fastcgi_params;

PS: 每次配置好Nginx后,记得要重启Nginx,使配置生效!

然后,修改CI框架中路由规则,在CI的Application/conf目录下,找到routes.php文件,在末尾添加:

$route['test1/test2/test3/(.+)'] = "$1";

之后 URL可为www.example.com:port/test1/test2/test3/class/function/arg,查看php的www.access.log可发现,nginx已经将链接重写为www.example.com:port/test1/test2/test3/index.php/class/function/arg,同样的由于Nginx默认监听端口号为80,所以当端口为80时可不加,其他端口要在URL中明确指明。

 

posted on   p_string  阅读(5148)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示