nginx を使用したサブディレクトリ内の CakePHP (ルールの書き換え?)

nginx を使用したサブディレクトリ内の CakePHP (ルールの書き換え?)

しばらく前にこれを動作させることができましたが、開始した cakephp プロジェクトに戻ると、最近 nginx に加えた変更 (または最近の更新) によって書き換えルールが破られているようです。

現在、私は以下を所有しています:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.php index.html index.htm;
        }

        location /basic_cake/ {
            index  index.php;

            if (-f $request_filename) {
              break;
            }
            if (!-f $request_filename) {
              rewrite ^/basic_cake/(.+)$ /basic_cake/index.php?url=$1 last;
              break;
            }
        }

        location /cake_test/ {
            index  index.php;

            if (-f $request_filename) {
              break;
            }
            if (!-f $request_filename) {
              rewrite ^/cake_test/(.+)$ /cake_test/index.php?url=$1 last;
              break;
            }
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

    server {
        listen       8081;
        server_name  localhost;

        root /srv/http/html/xsp;

        location / {
            index  index.html index.htm index.aspx default.aspx;
        }

        location ~ \.(aspx|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)$ {
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

}

私が抱えている問題は、CSSと画像がウェブルートから読み込まれないことです。代わりに、http://localhost/basic_cake/css/cake.generic.css、次のようなページが表示されます:

CakePHP: 迅速な開発を可能にする PHP フレームワーク コントローラーが見つかりません

エラー: CssController が見つかりませんでした。

エラー: 以下のファイル内に CssController クラスを作成してください: app/controllers/css_controller.php

注意: このエラーメッセージをカスタマイズしたい場合は、app/views/errors/missing_controller.ctp を作成してください。CakePHP: 迅速な開発を可能にする PHP フレームワーク

これを修正する方法について何かアイデアをお持ちの方はいらっしゃいますか?

答え1

最終的には回避策を使用しました。Apache をインストールし、proxy_pass nginx ディレクティブを使用して、特定のフォルダーからのトラフィックを Apache にプッシュしました。

答え2

問題は書き換えルールにあると思います。次のようになります

location / {
    root /home/public_html/sub.example.com/cake/app/webroot;
    index index.php;

    if (-f $request_filename) {
        break;
    }
    if (!-f $request_filename) {
        rewrite ^/(.+)$ /index.php?url=$1 last;
        break;
    }
}

私も同様の問題を抱えていましたが、これで解決しましたcakephp と nginx の設定/書き換えルール

関連情報