CodeIgniter在nginx下rewrite配置問題

昨天在服務器上安裝了Codeigniter,同時修改了nginx相關配置,ci能夠正常運行了。php

但今天在作表單提交時又出現了問題,問題以下:html

在我以前的rewrite配置下,ci的正常url爲http://localhost/example/news/ 此url能夠正常訪問nginx

http://localhost/index.php/example/news/ 此url返回404頁面服務器

ci中生成form的函數 open_form('example/news')默認的提交action爲http://localhost/index.php/example/news/app

因此當我提交表單時老是提示404錯誤,開始我覺得是form表單出了問題,可查閱資料後發現本身的寫法並無問題,然後發現訪問上面兩個url出現了不一樣頁面,正常狀況下二者應該相同,就此我斷定應該是url重寫或者是ci配置有問題。函數

查閱資料後發現,在application/config/config.php中的$config['index_page']要從新設置。url

默認的配置
$config['index_page'] = 'index.php';
此處要改成
$config['index_page'] = '';

同時要注意code

uri_protocol配置要改成
$config['uri_protocol'] = 'PATH_INFO';

nginx配置也要修改orm

server {
    listen       80;
    server_name  test;
        

    rewrite_log on;
    error_log /data/logsnginx/test_nginx_error.log info;
    

    location / {
        index index.html index.htm index.php;
        root  /data/www/test;
        

        if (!-f $request_filename){
            rewrite ^(.*)$ /index.php$1;
        }
    }

    location ~ \.php($|/) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
相關文章
相關標籤/搜索