Nginx+CI出現404錯誤,nginxci404錯誤_PHP教程

來源:互聯網
上載者:User

Nginx+CI出現404錯誤,nginxci404錯誤


最近剛學ci架構,做了個簡單的項目,在本地搭伺服器的環境都調通了,但是部署到遠程伺服器時:

http://example.com/(index.php)/ 可以訪問(為配置的預設controller-class)

http://example.com/(index.php)/[controller-class]/[controller-method] 不可以訪問(提示404錯誤!)

最後百度原因:

對於/index.php/abc這種url,Apache和Lighttpd會按”index.php?abc”來解釋,而nginx會認為是請求名字是“index.php”的目錄下的abc檔案的內容。所以CI在nginx下不配置rewrite是無法啟動並執行,而在Apache和Lighttpd則正常。 解決方案(要點加 ,重點標紅):
 1   server { 2         listen 80; 3         server_name example.com; 4         root /data/wwwroot/example/ 5         index index.php index.html index.htm; 6  7         location ~* \.(css|js|swf|htm|jpg|png|gif|json|atlas)?$ { 8             expires 1d; 9             add_header Pragma public;10             add_header Cache-Control "public";11         }12         13         location /controller-class/ {14             if (!-e $request_filename) {15                 rewrite ^/controller-class/(.*)$  /controller-class/index.php?q=$uri&$args;16             }17         }18  19         location ~ \.php$ {20             fastcgi_pass   127.0.0.1:9000;21             fastcgi_index  index.php;22             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;23                         fastcgi_param  PHP_VALUE        open_basedir=$document_root:/tmp/:/proc/;24             include        fastcgi_params;25         }26 27     }

參考資料:http://www.2cto.com/os/201301/185926.html【Nginx+CI出現404錯誤問題】

http://www.bkjia.com/PHPjc/1105554.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1105554.htmlTechArticleNginx+CI出現404錯誤,nginxci404錯誤 最近剛學ci架構,做了個簡單的項目,在本地搭伺服器的環境都調通了,但是部署到遠程伺服器時: http:...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.