codeigniter(CI)是一個(gè)輕量型的PHP優(yōu)秀框架,但是它是在apache服務(wù)器下開發(fā)的,在nginx下需要特別的配置才可以使用。
第一,對(duì)application/config/config.php進(jìn)行修改,大約在48行左右。
修改為 $config['uri_protocol'] = 'PATH_INFO';
第二,修改nginx配置
server {
? ? ? ? listen? ? ? 80;
? ? ? ? listen [::]:80 ipv6only=on;
? ? ? ? server_name? www.example.com;
? ? ? ? root? /data/www/www.example.com;
? ? ? ? index index.php? index.html index.htm;
? ? ? ? location / {
? ? ? ? ? ? ? ? # 這里使用try_files進(jìn)行url重寫,不用rewrite了。
? ? ? ? ? ? ? ? try_files $uri $uri/ /index.php?$query_string;
? ? ? ? }
? ? ? ? location ~ \.php($|/) {
? ? ? ? ? ? fastcgi_pass? 127.0.0.1:9000;
? ? ? ? ? ? fastcgi_index? index.php;
? ? ? ? ? ? fastcgi_split_path_info ^(.+\.php)(.*)$;
? ? ? ? ? ? fastcgi_param? PATH_INFO $fastcgi_path_info;
? ? ? ? ? ? fastcgi_param? SCRIPT_FILENAME? $document_root$fastcgi_script_name;
? ? ? ? ? ? include? ? ? ? fastcgi_params;
? ? ? ? }
? ? ? ? location ~ /\.ht {
? ? ? ? ? ? ? ? deny? all;
? ? ? ? }
}
要特別注意19行的include fastcgi_params;,如果沒有這一行,那么你的PHP程序會(huì)無法運(yùn)行的。