首页 > 开发 > Nginx > 正文

Nginx下配置codeigniter框架方法

2021-11-24 20:13:05
字体:
来源:转载
供稿:网友

由于项目迁移,不得不在Nginx下配置codeigniter框架,开始怎么配置都不成功,经过度娘以及众网友的热心帮忙,终于完成了正确的设置,这里分享给大家,有需要的小伙伴参考下.

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

1、修改网站配置文件,代码如下:

  1. server { 
  2.     listen 80; 
  3.     server_name example.com;//自己的域名 
  4.     root /alidata/www/example;//网站目录 
  5.     index index.php index.htm index.html; 
  6.     location / { 
  7.             try_files $uri $uri/ /index.php; 
  8.     } 
  9.     location /index.php{ 
  10.         fastcgi_pass  127.0.0.1:9000; 
  11.         fastcgi_param SCRIPT_FILENAME /alidata/www/example/index.php; 
  12.         fastcgi_param PATH_INFO $fastcgi_path_info
  13.         fastcgi_split_path_info ^(.+/.php)(.*)$; 
  14.         fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info
  15.         include  fastcgi.conf; 
  16.     } 

2、修改CI 的config.php 文件,代码如下:

  1. $config['base_url']     = 'http://example.com/'
  2. $config['uri_protocol'] = 'PATH_INFO';//貌似REQUEST_URI也行 
  3. $config['index_page'] = ''

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

4、重启nginx

上一篇:nginx常用设置

下一篇:返回列表

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表