已经两天了,我试图弄清楚如何在服务器上正确设置一个苗条的框架。
我最后一次尝试使用本指南https://github.com/slimphp/Slim,而我的nginx配置文件是
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/prova/public;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
我已经按照指南创建了文件夹/var/www/prova
,并按照指南的说明安装了组件,然后创建了/var/www/prova/public
文件夹以编写index.php
格式如下
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
// Instantiate App
$app = AppFactory::create();
// Add error middleware
$app->addErrorMiddleware(true, true, true);
// Add routes
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write('<a href="/hello/world">Try /hello/world</a>');
return $response;
});
$app->get('/hello/{name}', function (Request $request, Response $response, $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
目前有2个问题:
MY_IP/hello/Ryan
时,它可以工作并显示hello, Ryan
,但是当我检查根目录MY_IP/
时,我得到403 Forbidden nginx/1.16.1
-当我尝试使用
从我的typecritp Web应用程序中的组件调用apiMY_IP/hello/Ryan
时
const data = {
email: 'email@gmail.com',
password: 'asdfasd'
};
this.http.get('http://MY_IP/hello/sss').subscribe((res) => {
console.log(res);
});
我得到了
Request URL: http://MY_IP/hello/sss
Referrer Policy: no-referrer-when-downgrade
Provisional headers are shown
Accept: application/json, text/plain, */*
Referer: http://localhost:4200/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36 OPR/64.0.3417.61
显然有些设置没有正确配置。
在此先感谢您的帮助。