2017-09-18 14 views
1

それをロードする私は、次のnginxのtry_filesダウンロードのphpファイルの代わりに、

x.com opens index.php in/

x.com/example opens example.php in/

x.com/example/ opens example.php in/

x.com/foo/example opens example.php in /foo/ 

を達成するために、私のnginxのサーバーをセットアップしようとしている私は、このセットアップでは、次のような構成

server { 
listen www.delibr.com:443 default_server; # if this is not a default server, remove "default_server" 
root /var/delibr.se; 
index index.php index.html index.htm; # this is also irrelevant 

server_name www.delibr.com; 
ssl_certificate /path to/crt; 
ssl_certificate_key /path to/key; 

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
ssl_prefer_server_ciphers on; 
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL; 

location /beta { 
    return 302 /#signup-form; 
} 

location/{ 
    try_files $uri $uri.php $uri/; 
    if ($host != 'www.delibr.com') { 
     rewrite ^https://www.delibr.com$request_uri? permanent; 
    } 
} 

location ~ [^/]\.php(/|$) { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 

    # With php5-fpm: 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
    } 

} 

を持っています/ example example.phpと/ example /をダウンロードすると、500 Internal Serverエラーが発生します。誰でも助けてくれますか?

答えて

1

あなたtry_files

try_files $uri $uri/ $uri.php; 

次のように最後のものを除くすべてのパラメータは、現在のコンテキストでテストされるべきです。したがって、あなたが$uri.phpを使用し、そのファイルが見つかると、現在のコンテキストはそれを静的ファイルとして提供することを意味します。しかし、最後のパラメータでは、設定内の他の場所のブロックと照合します。

編集-1

x.com/example/ opens example.php in /のためのあなたの要求は通常のものではありません、それを動作させるために少しトリッキーでした。 $uri.phptry_filesに設定すると、URLがx.com/example/.phpに変更されます。したがって、追加のブロックを1つ追加することで、このURLを追加で処理する必要があります。

location ~* /\.php { 
    rewrite ^(.*)/\.php$ $1.php redirect; 
} 
+0

ありがとうございました!ほとんど働いた。しかし、 'x.com/example/はexample.phpを/で開きます。' 'No input file specified 'が生成されます。 – fbonawiede

+0

はい、私は何かを素早くチェックさせてもらえますか? –

+0

私は '書き換え^ /($ 1 $)$/$ 1パーマネント 'を追加しようとしましたが、それは解決しますが新しい問題が発生します。実際にindex.htmlを持つサブフォルダは機能しません。 – fbonawiede

関連する問題