【问题标题】:GAE PHP - Error page displays locally but not when deployedGAE PHP - 错误页面在本地显示,但在部署时不显示
【发布时间】:2015-07-09 16:38:10
【问题描述】:

在本地(通过应用引擎启动器)提供服务时,会显示 error.html 页面,但在部署时,当我收到 404/etc 响应时,它不会解析为错误页面。

我部署了新版本,但也没有用。我的 YAML 文件有什么问题吗?或者有人有其他建议吗?

谢谢

YAML 文件

application: xxxmeowxxx
version: 1-5
runtime: php55
api_version: 1

handlers:
# Serve as static resources.
- url: /img
  static_dir: img
- url: /css
  static_dir: css
- url: /js
  static_dir: js
- url: /fonts
  static_dir: fonts
- url: /Documents
  static_dir: Documents


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

#serve php scripts without needing .php
- url: /(.+)
  script: \1.php

#serve index 
- url: /
  script: index.php

#Error handle
error_handlers:
  - file: error.html

【问题讨论】:

    标签: php google-app-engine


    【解决方案1】:

    唯一支持的错误类型是

    • over_quota,表示应用已超出资源配额;
    • dos_api_denial,提供给被应用的 DoS 保护配置阻止的任何客户端;
    • 超时,如果在您的应用响应之前到达最后期限,则提供。

    更多详情请见https://cloud.google.com/appengine/docs/php/config/appconfig#PHP_app_yaml_Custom_error_responses

    要获得 404 错误页面,只需在 index.php 之后添加一个包罗万象的处理程序 (/.*) 即可打印出内容。

    【讨论】:

    • 谢谢,但这不是问题所在。我的 YAML 和错误捕获在本地工作,但在部署时它不起作用。我发现它与 YAML 文件中的 -> url: /(.+) 有关。这是在部署时不允许显示错误页面但又在本地工作的部分。
    【解决方案2】:

    我发现处理错误的最佳方法是创建路由器。您将在您的 yaml 中包含一个全部捕获(这将在您在 yaml 文件中声明的所有其他内容之后)并处理您的路由器文件中的所有请求。

    YAML

    #serve router
    - url: /(.*)
    script: /routes.php
    

    路由器文件

    $path       = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); //get full path
    

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 2019-05-25
      • 2021-06-29
      • 2019-04-06
      • 2015-12-07
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多