SilverStripe

SilverStripe はNGINX上で楽しく動作する最新のPHPベースのCMSフレームワークです。

rewriteルール内でどのようなエラーも修正しようとする組み込みのフェイルセーフがあります。 rewrite rules. まず、SSはURLをどう処理するかを定義するために.htaccess に依存します。次に、rewriteが失敗した場合、index.php ファイルは内部変数を設定し、処理のためにコア/sapphire/main.php ファイルをincludeしようとするでしょう。

注意

これらの指示は、あなたがPHPをPHP FastCGIの例 あるいは 127.0.0.1:9000 上でlistenしている PHP-FPM として設定したものを使っていると仮定します。環境で必要であれば、fastcgi_paramsに適切な変更をしてください。

Recipe

全てのSilverStripeコールを制御する基本的なrewriteは、URIと任意のGET変数の$document_root/framework/main.phpへの渡しを伴います。

  1. SilverStripeインストレーションのroot内の.htaccess ファイルとindex.phpを削除します(確実にそうしてください)
  2. 以下に似た設定を適用します:
server {
    listen 80;
    root /path/to/ss/folder;

    server_name site.com www.site.com;

    location / {
        try_files $uri /framework/main.php?url=$uri&$query_string;
    }

    error_page 404 /assets/error-404.html;
    error_page 500 /assets/error-500.html;

    location ^~ /assets/ {
        sendfile on;
        try_files $uri =404;
    }

    location ~ /framework/.*(main|rpc|tiny_mce_gzip)\.php$ {
        fastcgi_keep_conn on;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /(mysite|framework|cms)/.*\.(php|php3|php4|php5|phtml|inc)$ {
        deny all;
    }

    location ~ /\.. {
        deny all;
    }

    location ~ \.ss$ {
        satisfy any;
        allow 127.0.0.1;
        deny all;
    }

    location ~ web\.config$ {
        deny all;
    }

    location ~ \.ya?ml$ {
        deny all;
    }

    location ^~ /vendor/ {
        deny all;
    }

    location ~* /silverstripe-cache/ {
        deny all;
    }

    location ~* composer\.(json|lock)$ {
        deny all;
    }

    location ~* /(cms|framework)/silverstripe_version$ {
        deny all;
    }

    location ~ \.php$ {
                fastcgi_keep_conn on;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
    }
}