php - Google Cloud App Engine app.yaml php72 路由问题

标签 php google-app-engine google-cloud-platform app.yaml

我有一个核心 php 网站,这是我当前的 app.yaml 配置

runtime: php72

handlers:
# Serve a directory as a static resource.
- url: /assets
  static_dir: assets

- url: /css
  static_dir: css

- url: /js
  static_dir: js

- url: /ckeditor
  static_dir: ckeditor

# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
  static_files: \1
  upload: .+\.(gif|png|jpg)$

# add all script entries like this
- url: /login.php
  script: auto

# Serve your app through a front controller at index.php or public/index.php.
- url: .*
  script: auto

此配置的问题在于它一次又一次地重定向(302)到登录页面......并以错误太多重定向结束。

我错过了什么?

GAE 日志:
2019-01-18 17:10:07 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:10 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:13 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:16 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:19 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:22 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:10:25 default[20190118t223420]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:32:26 default[20190118t225141]  "GET / HTTP/1.1" 302
2019-01-18 17:32:26 default[20190118t225141]  nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3
2019-01-18 17:32:30 default[20190118t225141]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:32:33 default[20190118t225141]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:54:59 default[20190118t230733]  "GET / HTTP/1.1" 302
2019-01-18 17:55:00 default[20190118t230733]  nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3
2019-01-18 17:55:02 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:05 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:07 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:09 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 17:55:11 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:29 default[20190118t230733]  "GET / HTTP/1.1" 302
2019-01-18 18:17:32 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:35 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:37 default[20190118t230733]  "GET /login.php HTTP/1.1" 302
2019-01-18 18:17:40 default[20190118t230733]  "GET /login.php HTTP/1.1" 302

最佳答案

事实证明,php72 不支持标准环境直接执行脚本。一切都需要通过自定义 FrontController。所以我创建了一个 FrontController 来处理基本上所有的路由。下面是我放在 index.php 中的代码。它将处理所有指定的路由。

switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {
    case '/':
        require 'login.php';
        break;
    case '/product.php';
        require 'product.php';
        break;
    default:
        break;
}

您可以在此处找到用于自定义 FrontController 和不同框架的 php72 示例。 https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine/php72

感谢大家的努力。希望这能帮助像我这样迷失的灵魂。

关于php - Google Cloud App Engine app.yaml php72 路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54259307/

相关文章:

来自 jQuery $.post 的 PHP session

php - 最佳 PHP 图像裁剪类

php - Yii 在模型中创建新属性不起作用

java - 是否可以再调试 GWT?

python - 在 App Engine 中检测和重定向移动浏览器的最佳方法是什么?

php - 获取 strtotime 以查找给定时间的下一个时间戳

python - ndb 模型 - 检索有序的属性名称集

node.js - Node.js 和 MongoDB 应该在不同的 pod 中吗?

python - 通过 Firestore 触发事件简化 python 中的字典

google-cloud-platform - 数据流设置 Controller 服务帐户