1

サブディレクトリwww.mysite.com/shop/でLemonstandを実行しています

レモンスタンドのロケーションルールは次のとおりです。

# Lemonstand
location /shop {
    root /home/sites/mysite.com/public_html/shop/;
    index index.php;

    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param SCRIPT_NAME index.php;
    fastcgi_param QUERY_STRING url=$uri&$args;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 32k;
    fastcgi_busy_buffers_size 64k;
}

mysite.com/shopのページにアクセスできます。

ショップのすべてのURLは次のようになります

mysite.com/shop/category/freight
mysite.com/shop/products/dog-toy

実際にページ上にある場合、それらは次のように構成されています。

mysite.com/category/freight
mysite.com/products/dog-toy

そして奇妙なことに、ブラウザに正しいURLを貼り付けても、他のページが存在しないかのように、ベースの/shop/ページしか表示されません。誰か助けてもらえますか?

4

2 に答える 2

0

別の場所のブロックからphpを提供する必要があります。

[編集]他のphpスクリプトとの競合を避けるために、名前付きの場所を使用できます。

location ^~/shop/ {
    root /home/sites/mysite/public_html;

    try_files $uri $uri/ @anotherPhpSite
}

location @anotherPhpSite {
    include fastcgi_params;

    # Defend against arbitrary PHP code execution
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    # More info:
    # https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_param SCRIPT_FILENAME $document_root/shop/index.php;
    fastcgi_param SCRIPT_NAME /shop/index.php;
    fastcgi_param QUERY_STRING url=$uri&$args;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 32k;
    fastcgi_busy_buffers_size 64k;

}
于 2013-03-21T12:43:34.613 に答える
0

私の主な問題は、式の構文と構成構造でした。

わかった。これが動作する設定ファイルです。ベストプラクティスは、2つの場所を分割し、両方に1つのphpブロックを使用することでした。

まず、silverstripe CMSを使用するメインコントローラーブロックです。ここでは、サファイアのメインコントローラーにデータを直接渡します。

# Main silverstripe declaration
location / {
    index /sapphire/main.php;
    try_files $uri $uri/ /sapphire/main.php?url=$uri&$args;
}

2つ目は、lemonstandを実行しているサブディレクトリの下にある私のショップでした。これは主に、式を正しく取得してから、関連するパスにリクエストを渡す場合でした。ルールはリライトから継承されたため、ここでは別のルートまたはエイリアスを設定しませんでした。

# Shop lemonstand files
location /shop/ {
    index index.php;
    rewrite ^/shop(.*)$ /shop/index.php?q=$1 last;
    try_files $uri $uri/ /shop/index.php?q=$1;
}

そして最後に、汎用PHPブロックを使用したので、最初の2つでコードを複製する必要はありませんでした。したがって、最初の2つのブロックを通過するものはすべてここに渡されます。

# PHP controller
location ~ ^(.*?\.php)(/.*)?$ {
    fastcgi_split_path_info ^(.+?\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_pass 127.0.0.1:9000;

    fastcgi_index index.php;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 32k;
    fastcgi_busy_buffers_size 64k;
}
于 2013-03-27T09:47:02.030 に答える