2

PHP-FPMルールをNginxリライトルールとうまく連携させるにはどうすればよいですか?

現在の設定ファイル

server {

location / {

  location ~ \.php$ {
   try_files        $uri =404;
   fastcgi_split_path_info  ^(.+\.php)(/.+)$;
   fastcgi_pass     127.0.0.1:9000;
   fastcgi_param        PATH_INFO   $fastcgi_path_info;
   fastcgi_param        PATH_TRANSLATED $document_root$fastcgi_script_name;
   include          fastcgi.conf;
  }

  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php?routestring=$1 break;
  }

    rewrite ^/(admincp/)$ /index.php?routestring=$1 break;

  }
}
4

1 に答える 1

4

ロケーションブロックを次のように変更します。また、ステートメントを避けるようにしてifください、それについて(そしてもっと)ここで読んでください:http ://wiki.nginx.org/Pitfalls

if (!-e ...)以下の設定で、パーツを@missingブロックに置き換えました。

server {
    root /your/root/path
    index index.php index.html index.htm;

    server_name your.domain.com;

    rewrite ^/(admincp/)$ /index.php?routestring=$1 break;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.php
            try_files $uri $uri/ /index.php?$args;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
            # Move to the @missing part when the file doesn't exist
            try_files $uri @missing;

            # Fix for server variables that behave differently under nginx/$
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # Include the standard fastcgi_params file included with ngingx
            include fastcgi_params;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_index index.php;

            # Override the SCRIPT_FILENAME variable set by fastcgi_params
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$

            # Pass to upstream PHP-FPM; This must match whater you name you$
            #fastcgi_pass phpfpm;
            fastcgi_pass 127.0.0.1:9000;
    }

    location @missing {
            rewrite ^(.*)$ /index.php?routestring=$1 break;
    }
}
于 2012-11-13T16:42:13.417 に答える