【问题标题】:REST API call returns 404 error in Google App Engine with PHP Yii2 frameworkREST API 调用在使用 PHP Yii2 框架的 Google App Engine 中返回 404 错误
【发布时间】:2018-07-27 08:20:19
【问题描述】:

我的应用程序包含 Angular 和 Php Yii2 框架。

我在 Google App Engine 上托管了我的应用程序。

这是我的 app.yaml 文件的内容:

threadsafe: true
runtime: php55
api_version: 2

handlers:

# The root URL (/) is handled by the Go application.
# No other URLs match this pattern.

- url: /(.+)
  static_files: \1
  upload: (.*)

- url: /web-service/*
  script: web-service/yii

- url: /
  static_files: index.html
  upload: index.html

我的 Yii2 库在 web-service 目录中可用,但是当我从邮递员调用 REST API 时,它会返回“404 page not found”错误。

我的 app.yaml 文件中是否缺少某些内容?

请帮我解决这个问题。我的 API 调用是这样的:

https://abcxyz.appspot.com/web-service/web/user-registration/login-user

【问题讨论】:

    标签: google-app-engine google-cloud-platform


    【解决方案1】:

    几个问题:

    • api_version: 2 - 目前没有这样的版本,设置为1。从 Syntax 表中的 api_version 行:

      此时,App Engine 有一个版本的 php 运行时 环境:1

    • app.yaml 中处理程序的顺序很重要,将使用第一个匹配模式的处理程序。您的url: /(.+) 模式也将匹配您的所有/web-service/* 请求,因此将尝试上传静态文件而不是您期望的脚本。使用最重要的模式在不太重要的模式之前重新排序您的处理程序。

    • 如果需要从 web-service 目录提供其他 php 文件,则您的 script: web-service/yii 条目可能不正常(无论请求的脚本如何,web-service/yii 始终是提供的文件)。相反,我会使用Example 中建议的处理程序(假设脚本名称总是以.php 结尾):

      # Serve php scripts.
      - url: /(.+\.php)$
        script: \1
      

    始终检查开发服务器日志中的请求条目,作为调试请求失败的起点。

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 2016-07-17
      • 2017-06-12
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多