9

こんにちは誰かが私を助けてください、私はファクトCGIでNginxを実行しているCentosサーバー上にcakephp環境をセットアップしようとしています。サーバー上でWordPressサイトとphpmyadminサイトを既に実行しているので、PHPを正しく構成しています。

私の問題は、ケーキがページを正しくレンダリングするように、つまりスタイリングなどで、仮想ホストで書き換えルールを正しく設定できないことです。私は可能な限りグーグルで検索しましたが、以下のようなサイトからの主なコンセンサスは、次の書き換えルールを設定する必要があるということです。

location / {
          root   /var/www/sites/somedomain.com/current;
          index  index.php index.html;

          # If the file exists as a static file serve it 
          # directly without running all
          # the other rewrite tests on it
          if (-f $request_filename) { 
            break; 
          }
          if (!-f $request_filename) {
            rewrite ^/(.+)$ /index.php?url=$1 last;
            break;
          }
        }

http://blog.getintheloop.eu/2008/4/17/nginx-engine-x-rewrite-rules-for-cakephp

問題は、これらの書き直しは、私がやりたいことではないWebルートから直接ケーキを実行することを前提としていることです。各サイトの標準設定があります。つまり、サイトごとに1つのフォルダーがあり、ログ、バックアップ、プライベート、およびパブリックのフォルダーが含まれています。パブリックはnginxが提供するファイルを探している場所ですが、私はケーキをプライベートにインストールし、パブリックにシンボリックリンクを付けて/ private/cake/にリンクしています。

これは私の仮想ホストです

server {
            listen      80;
            server_name app.domain.com;

            access_log /home/public_html/app.domain.com/log/access.log;
            error_log /home/public_html/app.domain.com/log/error.log;

  #configure Cake app to run in a sub-directory
  #Cake install is not in root, but elsewhere and configured
  #in APP/webroot/index.php**

                location /home/public_html/app.domain.com/private/cake {
                index index.php;

    if (!-e $request_filename) {
        rewrite ^/(.+)$ /home/public_html/app.domain.com/private/cake/$1 last;
        break;
    }
}

                location /home/public_html/app.domain.com/private/cake/ {
                index index.php;

    if (!-e $request_filename) {
        rewrite ^/(.+)$ /home/public_html/app.domain.com/public/index.php?url=$1 last;
        break;
        }
}

         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /home/public_html/app.domain.com/private/cake$fastcgi_script_name;
            include        /etc/nginx/fastcgi_params;
        }

 }

私が言ったように、ケーキのメインのindex.phpを見て、それをDBに接続しましたが、このページにはスタイルがないので、先に進む前に、正しく構成したいと思います。私は何が間違っているのですか?

ありがとうseanl

4

6 に答える 6

9

一見したところ、nginx がアプリの webroot を指していないことが問題である可能性があります。ルートの Cake フォルダーにデプロイすることは、Web サーバーの下に移動する方法ではありません。

以下は、私が実行中の Cake アプリを使用する完全なサーバー ブロックです。実際には、最初の 4 行しかなく、別のファイル「cakephp.inc」から残りを含めます。

「fastcgi_param SERVER_NAME $host;」行のメモ。これは、一部のアプリが $_SERVER['SERVER_NAME'] を使用しており、nginx では Apache と同じ意味を持たないためです。サーバーに複数の server_name(s) が定義されている場合、nginx は常に最初のものを php に渡します。

server { 
    server_name  cakeapp.example.com;
    root   /var/www/vhosts/cake/app/webroot;
    access_log  /var/log/nginx/cakeapp.access.log;
    error_log   /var/log/nginx/cakeapp.error.log;

    listen       80;
    rewrite_log on;

    # rewrite rules for cakephp
    location / {
        index  index.php index.html;

        # If the file exists as a static file serve it 
        # directly without running all
        # the other rewite tests on it
        if (-f $request_filename) { 
            break; 
        }
        if (!-f $request_filename) {
            rewrite ^/(.+)$ /index.php?url=$1 last;
            break;
        }
    }

    location ~* \favicon.ico$ {
        expires 6m;
    }
    location ~ ^/img/ { 
        expires 7d; 
    } 

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SERVER_NAME $host;
    }

    location ~ /\.ht {
        deny  all;
    }
}
于 2009-07-09T07:41:45.543 に答える
7

この問題に関する公式ドキュメントがあり、私はこれを使用して作業を確認しました。

ドキュメントには次のように記載されています。

server {
  listen   80;
  server_name www.example.com;
  rewrite ^(.*) http://example.com$1 permanent;
}

server {
  listen   80;
  server_name example.com;

  # root directive should be global
  root   /var/www/example.com/public/app/webroot/;
  index  index.php;

  access_log /var/www/example.com/log/access.log;
  error_log /var/www/example.com/log/error.log;

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index   index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}
于 2011-08-16T00:13:30.347 に答える
4

私はこれを機能させました:

root DIR/app/webroot/;
location / {
    index index.php index.html;
    rewrite ^/$ /index.php?url=/;
    if (!-e $request_filename) {
        rewrite ^(/.*)$ /index.php?url=$1 last;
    }
}

そしてもちろんphpなどのハンドラー...

于 2010-06-15T22:15:22.613 に答える
2

'location' ブロック内で 'IF' ブロックを使用することはお勧めできません。

正規表現の場所を使用して、同じことを達成するためのより自然な方法を次に示します。

この例では、CakePHP 2.xが vhost のルート アプリです ( server_name 、ログなどの一般的なものはスキップされます):

 root   /path/to/cakephp-2.x_root/app/webroot;
 index index.php;

 location ~ .+\.php$ {
        try_files $uri =404; #handle requests for missing .php files
        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:7001; #the FPM pool port
    }


    location ~ ^/(.*) {
        try_files $uri $uri/ /index.php?url=$1&$args;
    }

.php ロケーション ブロックは / ロケーション ブロックの前にあることに注意してください。正規表現の場所では、最初の一致まで検索されるため、これは重要です。

http://www.example.com/something/などのサブロケーションで実行する必要がある場合は、次の方法で実行できます。まず、nginx をだますためにシンボリック リンクを作成する必要がありました。cakephp-2.x をどこかに抽出し、次に「app/webroot」で、サブロケーションと同じ名前でそれ自体へのシンボリック リンクを作成します。たとえば、「ln -s ../webroot something」 .

次に、次の構成は、/something/ の下にある cackephp にアクセスするために機能します。

    location ~ ^/something/.+\.php$ {
        try_files $uri =404; #handle requests for missing .php files
        root /path/to/cakephp-2.x_root/app/webroot;
        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:7001; #the FPM pool port
    }

    location ~ ^/something(?:/)(.*) {
        root /path/to/cakephp-2.x_root/app/webroot;
        index index.php;
        try_files $uri $uri/ /something/index.php?url=$1&$args;
    }

「ルート」の代わりに「エイリアス」を使用することで、おそらくシンボリックリンクを回避できますが、その方法がわかりませんでした。

于 2015-02-12T10:48:22.923 に答える
0

古いバージョンの CakePHP 1.2 を実行している CakePHP サイトをセットアップする際に、多くの問題がありました。私は最近それについてブログを書き、Cake ライブラリの新しいバージョンをアップグレードまたはインストールすることを提案しただけで、すべての問題が解消されました。

于 2012-09-15T17:42:59.770 に答える
0

以下のコードを使用してください

vi /etc/nginx/sites-available/domainname.com

server { 
server_name  cakeapp.example.com;
root   /var/www/vhosts/cake/app/webroot;
access_log  /var/log/nginx/cakeapp.access.log;
error_log   /var/log/nginx/cakeapp.error.log;

listen       80;
rewrite_log on;

# rewrite rules for cakephp
location / {
    index  index.php index.html;

    # If the file exists as a static file serve it 
    # directly without running all
    # the other rewite tests on it
    if (-f $request_filename) { 
        break; 
    }
    if (!-f $request_filename) {
        rewrite ^/(.+)$ /index.php?url=$1 last;
        break;
    }
}

location ~* \favicon.ico$ {
    expires 6m;
}
location ~ ^/img/ { 
    expires 7d; 
} 

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SERVER_NAME $host;
}

location ~ /\.ht {
    deny  all;
}

}

それは私のために働いています。

于 2014-12-09T06:06:22.370 に答える