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

[初级] CI3.x Nginx下 支持 PATH_INFO 的成功分享

[复制链接]
发表于 2017-1-17 17:03:04 | 显示全部楼层 |阅读模式

把 CI3.X 项目放到 NGINX下 默认是不支持 PATH_INFO 模式访问的,
在论坛 爬了几个帖子,没有找到合适的,期间在网上搜了很多 NGINX 配置支持 PATH_INFO的文章 , 试了很多都没成功.....
就想让我的CI3项目支持NGINX!  给新手一些帮助提示吧。
==================配置目的===============
http://www.weixin.com/content/show.html
http://www.weixin.com/category/list.html
通过以上URL能正常访问
但是加上index.php 就没法访问了
http://www.weixin.com/index.php/category.html  无法访问
=================项目环境================================
终于官网找到了 相关信息,
https://www.nginx.com/resources/ ... ecipes/codeigniter/
我在Vbox搭建的centos7 everything 服务器
用的是LNMP 1.3
后来升级了为 nginx 1.8.1
CI使用的是3.1.3
==================CI相关配置config.php===================
CI相关的配置是:
config.php
$config['base_url'] = 'http://www.weixin.com/';
$config['index_page'] = '';
$config['uri_protocol']        = 'REQUEST_URI';
$config['url_suffix'] = '.html';
===============CI相关配置routes.php==============
routes.php
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['category'] = 'web/category/index'; //栏目首页
$route['content'] = 'web/content/index'; //默认内容页 这个应该取消
$route['category/(:any)'] = 'web/category/list/$1'; //栏目列表页
$route['content/(:any)'] = 'web/content/list/$1'; // 栏目对应的内容列表页
$route['content/show/(:num)'] = 'web/content/show/$1'; //内容详情页


======================控制器目录======================
ci/application/controllers/web/Content.php
ci/application/controllers/web/Category.php
ci/application/controllers/web/Show.php
ci/application/controllers/web/Home.php

ci/application/controllers/Home.php

=================nginx 记住 是 我的是虚拟主机的配置 weixin.com.conf=============================
我没有修改nginx.conf文件, 而是 修改虚拟主机的 如我的 weixin.com.conf
添加以下内容:

PHP复制代码
 
location / {
      try_files $uri $uri/ /index.php;
}
 
location ~* \.php$ {
      fastcgi_pass 127.0.0.1:9000;
      include fastcgi.conf;
}
 
 
复制代码


就这么多了。
自己标记一下
 楼主| 发表于 2017-1-17 17:20:57 | 显示全部楼层
刚看到,LNMP安装包 支持PATHINFO ,只需要把对应的虚拟主机的配置文件 将include enable-php.conf;替换为include enable-php-pathinfo.conf;

本版积分规则