首页 > 解决方案 > 错误 404 ngix - GAE php - 如何在 app.yaml 文件的处理程序属性中正确定义子文件夹?

问题描述

我对 app.yaml 文件定义有一些问题。我试图在 GAE 上部署一个简单的应用程序,但每次我尝试在https://myapp.appspot.com/api/v1/validate访问我的应用程序时总是会收到 404 错误:

这里的文件夹结构:

这是我的 app.yaml 代码:

  runtime: php
  env: flex

  runtime_config:
   document_root: web

  handlers:
  - url: /api/v1/validate/.*
    script: index.php

我做错了什么?先感谢您

标签: phpgoogle-app-enginehandlerapp.yaml

解决方案


我设法成功部署了类似的设置。这是我的更改:

访问网址: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


推荐阅读