在nginx环境下默认是不支持codeigniter框架的,如果需要在nginx环境下运行codeigniter框架,需要对系统环境做些修改。
修改方法:
1、修改CI项目配置文件,修改 uri_protocol 为 path_info
$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;}上述代码是针对入口文件为 index.php 的项目。
如果有多个项目需要根据入口文件添加相应项目配置,如:有前、后台2个项目,入口文件分别为index.php、admin.php,这时需要添加:
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;}location /admin.php{ fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_param SCRIPT_FILENAME /home/wwwroot/admin.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;}正常情况下,我们只需要修改以上2步就可以在nginx环境下正常运行codeigniter框架了。
但有时我们发现运行项目的过程中出现 No input file specified 的错误,原因是因为php没有开启对pathinfo的支持,只需要修改相应PHP配置项就可以了。
把:
cgi.fix_pathinfo=0改为:
cgi.fix_pathinfo=1重启nginx,即可。