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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM