php - 错误 404 ngix - GAE php - 如何在 app.yaml 文件的处理程序属性中正确定义子文件夹?
问题描述
我对 app.yaml 文件定义有一些问题。我试图在 GAE 上部署一个简单的应用程序,但每次我尝试在https://myapp.appspot.com/api/v1/validate访问我的应用程序时总是会收到 404 错误:
这里的文件夹结构:
- 应用程序.yaml
- 网络
- api
- v1
- 证实
- 索引.php
- 证实
- v1
- api
这是我的 app.yaml 代码:
runtime: php
env: flex
runtime_config:
document_root: web
handlers:
- url: /api/v1/validate/.*
script: index.php
我做错了什么?先感谢您
解决方案
我设法成功部署了类似的设置。这是我的更改:
访问网址:https ://YourProject.appspot.com/api/v1/validate/index.php
在 index.php 中将第 20 行修改为
require_once __DIR__ . '/../../../../vendor/autoload.php';
在 app.yaml 添加处理程序为:
runtime: php
env: flex
runtime_config:
document_root: web
handlers:
- url: /api/v1/authenticate
script: /api/v1/authenticate/index.html
- url: /api/v1/userprofile
script: /api/v1/userprofile/index.php
它工作得很好。
为此,我只是按照App Engine 灵活文档中的 PHP 快速入门,并将 helloworld 目录修改为
我的文件夹结构和你一模一样。
更新
在查看了您的代码后,我设法使用这些设置部署了一个应用程序
应用程序.yaml
runtime: php
env: flex
runtime_config:
document_root: web
handlers:
- url: /api/v1/authenticate
script: /api/v1/authenticate/index.html
- url: /api/v1/userprofile
script: /api/v1/userprofile/index.php
索引.php
<?php
include '../../utils.php';
require_once __DIR__ . '/../../../../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/', function () {
return 'Hello World';
});
$app->get('/goodbye', function () {
return 'Goodbye World';
});
// @codeCoverageIgnoreStart
if (PHP_SAPI != 'cli') {
$app->run();
}
// @codeCoverageIgnoreEnd
return $app;
?>
我看到的是您没有以正确的方式处理 http 请求。您可以查看上面添加的 index.php,如果您使用此代码替换您的 index.php 代码之一,您将看到 yaml 文件将允许您在https://YOUR_APP.devshell.appspot连接到您的应用程序.com/api/v1/userprofile/index.php
推荐阅读
- yii2 - 如果当前未登录应用程序,则在登录后重定向到特定页面
- c# - 如何使用 SkiaSharp 在 Xamarin 中创建简单的动画
- ada - Gnatchop 未解析文件
- angular - toString 的 ionic 4 最喜欢的问题并保存数据
- django - 使用 Django Rest Framework 计算对象
- python - 通过键列表在嵌套字典中附加(而不是替换)项目
- networking - 基于带有 PF_RING 的端口对入站流量进行优先级排序并将其路由到虚拟接口
- spring-batch - 在 spring 批处理应用程序上实现 graalvm 是否可以提高其性能
- node.js - 在腻子会话超时后,Angular 会话被终止
- sharepoint - 无法将共享点文件夹同步到本地设备