我正在尝试将 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 部分在路径中休息/。