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中明确指明。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端