404 在实时 Google App Engine 上,同时在本地 SDK 服务器上工作

404 on live Google App Engine, while working on local SDK server

我已经在 GAE 标准环境中部署了几个 PHP 应用程序,一切正常。

现在我正在部署一个新的应用程序,它在 gcloud SDK 提供的本地服务器上按预期工作(终端命令:dev_appserver.py --log_level=warning app.yaml)。

问题是,当我将其部署到实时 GAE 服务 (gcloud app deploy app.yaml --project myapp) 时,我收到 404 错误消息:

The page could not be found

No web page found for the web address: xxx
HTTP ERROR 404

app.yaml 看起来像这样:

runtime: php55
api_version: 1
threadsafe: true

skip_files:
- README.md
- package.json

handlers:

- url: /(.*\.html)
  script: mod_rewrite.php
  secure: always

- url: /(.*\..{2,})
  static_files: 
  upload: (.*\..{2,})
  secure: always

- url: /.*
  script: mod_rewrite.php
  secure: always

我还尝试添加指向特定文件的测试处理程序:

- url: /(mytest\.html)
  static_files: 
  upload: mytest.html
  secure: always

这样我就可以到达url了。但仅此而已。任何其他 url 都是 404.

一件有趣的事情是,在当前部署版本的 GAE 应用程序的 Versions 选项卡上,它指出该应用程序是 0 B,即使没有以前的版本,而它应该在 30 Mb 左右。部署的时候好像988的文件都上传了,也是因为我的网速慢,需要一段时间。

成功完成教程后,我尝试将整个项目重新部署到一个新项目,但我仍然遇到同样的问题。

经过几个小时的测试,我终于明白了问题所在。

在 GAE 中,当声明某个路径为静态时,它会被解释为非代码路径。因此,在 PHP 环境中使用 requireinclude 的脚本 运行 无法访问该路径中的所有文件,并且它们不会显示在已部署的代码调试器中。

出于这个原因,我将所有静态文件放在一个子文件夹中 (www),非静态文件 required by PHP 脚本放在另一个子文件夹下。

您也可以使用 application_readable 处理程序选项在应用程序代码中包含相应的静态文件。来自 Handlers element:

application_readable

Optional. Boolean. By default, files declared in static file handlers are uploaded as static data and are only served to end users. They cannot be read by an application. If this field is set to true, the files are also uploaded as code data so your application can read them. Both uploads are charged against your code and static data storage resource quotas.

像这样:

- url: /(.*\..{2,})
  static_files: 
  upload: (.*\..{2,})
  application_readable: true
  secure: always