1

我正在尝试将 GoogleAppEngine PHP/Flex 上的现有应用程序移动到 GoogleAppEngine PHP/Standard,以从标准引擎的功能中受益。

我的项目设置如下:

  • server/public_html/rest/index.php : Slim 框架,front_controller_file
  • server/src : php 应用程序代码
  • server/public_html/index.html : angularjs 应用程序(+此目录中的其他文件。

在 GAE PHP Flex 上,我的 app.yaml 如下:

api_version: 1

runtime: php
env: flex

skip_files:
        - ^db$
        - ^vendor$
        - ^Spotfire$
        - ^complete-sync\.sh$
        - ^phinx\.yml$
        - ^phinx-template\.yml$
        - ^selective-sync\.sh$

runtime_config:
  document_root: /app/public_html
  front_controller_file: /app/public_html/rest/index.php
  enable_stackdriver_integration: true
...

这样 Slim 框架就可以工作了

nginx-app.conf 在 /server/nginx-app.yaml

location / {
  # try to serve file directly, fallback to front controller
  try_files $uri /index.html$is_args$args;
}
location /rest {
  # try to serve file directly, fallback to front controller
  try_files $uri /rest/index.php$is_args$args;
}

location ~ \.php {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
}

现在,在 GAE PHP Standard 上,我的 app.yaml 对于后端是这样的:

runtime: php72
entrypoint: serve public_html/rest/index.php

runtime_config:
        document_root: public_html
        enable_stackdriver_integration: true

我的 dispatch.yaml 如下:


dispatch:
  # Send all rest traffic to the backend
  - url: "*/rest/*"
    service: default

  # Send the rest to the front (angularjs)
  - url: "*/*"
    service: front

和 nginx-app.conf 还是一样的。

当我到达应用程序的 url (example.com) 时,angularjs 应用程序正确加载,我可以看到登录屏幕。

如果我去 example.com/rest/index.php

我收到身份验证失败,这是预期的行为。

但是,如果我去

example.com/rest/authenticate

我得到一个 404,我仍然应该得到一个应用程序错误而不是 404。使用 nginx 重写规则,它应该将 URL 转换为:

example.com/rest/index.php?authenticate

另外,在我的代码中,我检查了路径,以排除某些公共页面(和身份验证)的身份验证检查路径

当我点击登录按钮时,在我的 flex 部署中,$path 是“authenticate”,这里是“/rest/authenticate”。

$path   = $request->getUri()->getPath   ();

关于如何调试的任何想法?

我觉得我可能只使用一项服务(默认),但是 example.com/ 指向 public_html/rest/index.php 这对我不利,因为我希望 / 成为 angularjs 应用程序和 REST 部分在路径中休息/。

4

1 回答 1

1

您的 index.php 文件中可能存在误导。查看您的不同情况以及身份验证页面引用了哪个 .php 文件,确保它与其他页面的身份验证相同。由于 dispatch.yaml 优先于所有其他路由方法,因此 index.php 和 dispatch.yaml 之间的行为可能会发生冲突。如果您很难对其进行故障排除,您可以直接从 index.php 进行一些测试来处理您的服务。您可能在不同的子文件夹中也有 authentication.php。

如果直接访问 example.com/rest/authenticate.php 时得到 200,那么 index.php 可能是罪魁祸首。由于 App Engine 的标准环境与 Flex 不同,这里有一些与您的情况相关的文档:

前端控制器:https ://cloud.google.com/appengine/docs/standard/php7/building-app/#initializing Dispatch.yaml:https ://cloud.google.com/appengine/docs/standard/php7/reference /dispatch-yaml入口点: https ://cloud.google.com/appengine/docs/standard/php7/runtime#application_startup

此外,更仔细地查看导致 404 的回溯可能会给您一些提示。

以下是从一种环境迁移到另一种环境时的一些一般指示(相反但仍然有用): https ://cloud.google.com/appengine/docs/flexible/php/migrating

干杯

于 2019-04-05T19:56:49.190 回答