2016-07-27 7 views
2

私は基本的なハローワールドGETエンドポイントで非常に基本的なスリムなアプリを作りました。スリムエンドポイントはPHP独自のサーバーで動作しますが、nginxでは動作しません

<?php 

require 'vendor/autoload.php'; 

$app = new Slim\App(); 

$app->get('/hello/{name}', function ($request, $response, $args) { 
    $response->write("Hello, " . $args['name']); 
    return $response; 
}); 

$app->run(); 

/hello/worldエンドポイントは、PHPの組み込みサーバーで実行すると想定されるように動作します。 しかし、nginxではありません。 404が見つかりません。

マイnginx_vhost(の/ etc/nginxの/サイト利用可能/ nginx_vhost)ファイルには、次のようになります。

私は間違っているつもりです
server { 
    listen 80; 
    server_name localhost; 

    root /var/www/; 
    index index.php index.html; 

    # Important for VirtualBox 
    sendfile off; 

    location/{ 
     try_files $uri $uri/ =404; 
    } 

    location ~* \.php { 
     include fastcgi_params; 

     fastcgi_pass unix:/var/run/php5-fpm.sock; 

     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_cache off; 
     fastcgi_index index.php; 
    } 
} 

答えて

1

nginx_vhostファイルを修正して、必要に応じて引数をSlimに渡せるようにする必要があります。

そのDocumentationから撮影:

server { 
    #..... 

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

    #.... 
} 
関連する問題