在Nginx下通過(guò)ci框架開(kāi)發(fā)項(xiàng)目時(shí),發(fā)現(xiàn)ci框架在nginx下是不能運(yùn)行的,在網(wǎng)絡(luò)上搜索了相關(guān)資料后可通過(guò)修改相關(guān)配置實(shí)現(xiàn)nginx支持PHP的ci框架。
1、修改ci框架的配置文件
修改$config['uri_protocol']值
改為:
$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;
}
如果有多個(gè)應(yīng)用,如:后臺(tái)應(yīng)用,可以多加一段以上代碼,并修改相應(yīng)入口文件:
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;
}