nginx + codeigniter 設定在 CentOS 7 上不起作用?

nginx + codeigniter 設定在 CentOS 7 上不起作用?

我是 nginx 的新手,嘗試在 StackOverflow 上尋找該問題,但在論壇上沒有找到確切的問題。成功安裝 nginx、MySQL 和 php-fpm 後,我測試了運行良好的 php.info。

我正在將 CodeIgniter 專案從 apache 伺服器移至 nginx。我編輯nginx.conf包含程式碼的文件

server {
    listen       80;
    server_name  173.249.40.xxx;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html/ci;
    index index.html index.htm index.php;

    location /ci {
        try_files $uri $uri/ /index.php;
    }        

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

它工作正常,php.info就像我的路徑一樣,http://173.249.40.xxx/ci/info.php但不適用於 CodeIgniter,controller name就像http://173.249.40.xxx/ci/index.php/Welcome呼叫時一樣。

CodeIgniter應用程式路徑是'/usr/share/nginx/html/ci/;'

請給我建議一些東西。我該如何修復它?

答案1

這是錯誤:

    location /ci {

因此,只有以 開頭的 URL 路徑/ci才會被封閉的try_files.這不是你想要的。

相反,您應該處理所有 URL,並使用

    location / {

答案2

我建議不要編輯該nginx.conf文件。僅編輯gzip一個新的包含資料夾(如include /etc/nginx/sites/enabled/*.conf;),註解掉原始包含行並在其中建立名為 com.mywebsite.conf 的設定檔到我之前提到的資料夾中。

這就是我過去的做法:

在我提到的新設定檔中,複製官方推薦的配置的內容,如果您修改系統的變量,它應該可以工作。

https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/

另外,將您的網站儲存在/var/www/html/mywebsite

相關內容