Nginx下配置codeigniter框架

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

1、修改网站配置文件

server {

 2     listen 80;

 3     server_name example.com;//自己的域名

 4 

 5     root /alidata/www/example;//网站目录

 6     index index.php index.htm index.html;

 7 

 8     location / {

 9             try_files $uri $uri/ /index.php;

10     }

11 

12     location /index.php{

13         fastcgi_pass  127.0.0.1:9000;

14         fastcgi_param SCRIPT_FILENAME /alidata/www/example/index.php;

15        fastcgi_param PATH_INFO $fastcgi_path_info;

16         fastcgi_split_path_info ^(.+\.php)(.*)$;

17         fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

18         include  fastcgi.conf;

19     }

20 

21 }

2、修改CI 的config.php 文件

$config['base_url']     = 'http://example.com/';

$config['uri_protocol'] = 'PATH_INFO';//貌似REQUEST_URI也行

$config['index_page'] = '';

3、网站根目录以及以下目录设置读写权限(777)

4、重启nginx

 

你可能感兴趣的:(CodeIgniter)