`
moqiang02
  • 浏览: 529145 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
文章分类
社区版块
存档分类
最新评论

Nginx支持PHP的CI框架

 
阅读更多

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 –


分享到:
评论

相关推荐

    CI框架PHP漫画小说二合一CMS网站系统源码

    Apache/Nginx + PHP (5.3 +) + MySQL(5.0 +),内附安装教程

    Nginx+CI框架出现404错误怎么解决

    最近刚学ci框架,做了个简单的项目,在本地搭服务器的环境都调通了,但是部署到远程服务器时: http://example.com/(index.php)/ 可以访问(为配置的默认controller-class) http://example.com/(index.php)/...

    漫画小说二合一CMS网站系统PHP源码_CI框架.zip

    CI框架PHP漫画小说二合一CMS网站系统源码 内置采集火车头接口带充值和会员功能 在PHP+MYSQL环境下运行的完善而强大的快速建站系统。 经过近多年的开发经验和技术积累,即将成为全网最强漫画+小说系统,在易用性...

    CI框架PHPCMS网站系统源码

    兼容性和面向场景 1、Windows 平台: IIS/Apache + ... │ │─system //CI框架目录 │─template //模板目录 │ │─admin //后台模板 │ │─install //系统安装模板 │ │─pc //前台PC端模版 │ │─wap //前

    Nginx下配置codeigniter框架方法

    原来在winserver+Apache环境下工作良好的一个微信公众号后台迁移到阿里云(环境:Ubuntu 64位 | PHP5.4 | Nginx1.6)下却频出 404,403,只能访问CI routes.php中设置的默认控制器等问题,后来上网查里下可能是路由...

    PHP的Symfony和CodeIgniter框架的Nginx重写规则配置

    Symfony国外很流行的php框架,目前国内用的相对较少,但是一定会在国内火起来. nginx重写规则如下 server { server_name jb51.net www.jb51.net; root /data/site/www.jb51.net; location / { # try to serve ...

    assets-bower-ci:php框架的前端资产管理

    资产-bower-ci php框架的前端资产管理工具特征只需要一个json配置文件支持压缩 js 和 css 文件。 支持依赖(但有一些错误 #26) 例子php 在example/php文件夹中运行index.php 。 您将看到一个页面,其中包含来自...

    PHP5框架lessPHP.zip

    简介 lessPHP是一个基于MVC模型构建的PHP5框架,它的主要特点就是轻量级、扩展性高、入手简单,哪怕是PHP新手都...IMVC 的规划以及实现 在M 与 C之间增加I(Interface)层 LIB库的整理 标签:lessPHP Web框架

    框架:用于构建网站,Web应用程序,Web IDE,命令行应用程序的框架

    morpho-os /框架 用于构建网站,Web应用程序,Web-IDE,命令行应用程序的框架。 当前状态 没有准备好。 API不稳定。 二手技术 开发: 服务器端/后端: Nginx的 PHP MySQL / MariaDB:可选,可用作DBMS...CI状态 执照

    128uu酒店分销预订系统 PHP版 v2.1.zip

    i.如果是apache,独立服务器用户请把.htaccess文件中的内容复制到http.conf中,如果是虚拟主机用户请将目录中的.htacess文件放到您所安装的根目录中。 ii.如果是iis独立主机用户请在安装好Rewrite模块后,将默认的...

    新云PHP人才招聘系统免费版v1.1.4

    数据库排序规则:utf8b4_unicode_ci PHP版本:PHP-7.3以上 Redis:Redis 4.0以上 redis开启方法:宝塔面板----PHP版本----安装扩展----redis 安装完毕后请检查数据表,目前一共是129个数据表。 注意:安装的时候,...

    HXCblog:php基于CI + layui开发的个人博客系统

    演示站部署环境:centos6.8 + nginx1.14.0 + mysql5.7 说明:本人非php程序员,技术粗浅,HXCblogv1.0精简版博客非常方便记笔记和学习之用,程序完整可用,保留该版本只为方便分享和交流。 博客地址: 项目地址: ...

    kChina.today:今天的中国

    kChina.today暂时没有上线,使用了轻量的CI框架,暂时处于开发阶段,如果你想加入那么请git clone到你的本机. kChina.today使用HTML5,css3,LessCSS,jQuery,jQuery.easing,php5,redis,macache ##kChina.today配置 如果您...

    Chemex资产管理运维平台-PHP

    3、创建一个数据库,命名任意,但记得之后填写配置时需要对应正确,并且数据库字符集为 utf8-general-ci。 4、下载 发行版 ,解压得到程序目录,放置到你想要放置的地方。 5、在项目根目录中,复制 .env.example ...

Global site tag (gtag.js) - Google Analytics