我用一个基本的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();
/ hello / world终结点可以像我使用PHP的内置服务器运行它时那样工作。但是,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;
}
#....
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句