我制作了一个非常基本的slim应用程序,只有一个基本的hello-world GET端点。
<?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();
当我使用PHP的内置服务器运行/hello/world端点时,它的工作方式与预期的一样。但nginx没有。我得到一个404没有找到。
我的nginx_vhost(/etc/nginx/sites-available/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;
}
}
我哪里错了?
您需要修改nginx_vhost
文件,以便根据需要将参数传递给Slim。
取自他们的文件:
server {
#.....
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
#....
}