Thomas
Thomas

Reputation: 1354

Google App Engine, 2 Services, dispatch.yaml: nginx-app.conf seems to no longer be taken into account

I'm trying to move an existing application on GoogleAppEngine PHP/Flex to GoogleAppEngine PHP/Standard to benefit from the features of the standard engine.

My project is setup as follow :

On GAE PHP Flex, my app.yaml was as follow :

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
...

And so that Slim Framework works

the nginx-app.conf was in /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;
}

Now, on GAE PHP Standard, my app.yaml is like this for the backend:

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

runtime_config:
        document_root: public_html
        enable_stackdriver_integration: true

and my dispatch.yaml is the following:

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

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

and the nginx-app.conf is still the same.

When I reach the URL (example.com) of the app, the angularjs app loading correctly, I can see the login screen.

if I go to example.com/rest/index.php

I get an authentication failure, which is the expected behaviour.

However, if I go to

example.com/rest/authenticate

I get a 404, and I should still get an application error instead of the 404. With the nginx rewrite rule, it should transform the URL to this:

example.com/rest/index.php?authenticate

Also, in my code I check the path, to exclude some path of authentication check, for some public page (and the authentication)

When I hit the login button, on my flex deployment, the $path was "authenticate" and here it's "/rest/authenticate".

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

Any idea on how to debug that?

I feel I could maybe use only one service (default), but example.com/ is pointing on the public_html/rest/index.php which is not good for me, since I want / to be the angularjs app, and the REST part with a rest/ in the path.

Upvotes: 1

Views: 749

Answers (1)

PYB
PYB

Reputation: 533

It is possible there is misdirection inside your index.php file. Take a look at your different cases and which .php file is referenced for the authentication page, making sure it is the same for authentication than the other pages. Since dispatch.yaml takes precedence over all other routing methods, you might have conflicting behavior between index.php and dispatch.yaml. You could do some testing handling your services directly from index.php if you have a hard time troubleshooting it. You might have authentication.php in a different subfolder as well.

If you get a 200 when accessing example.com/rest/authenticate.php directly, then index.php might be the culprit. Since the Standard environment for App Engine is different from Flex, here are some docs relevant to your situation:

Front controllers: https://cloud.google.com/appengine/docs/standard/php7/building-app/#initializing Dispatch.yaml: https://cloud.google.com/appengine/docs/standard/php7/reference/dispatch-yaml Entrypoint: https://cloud.google.com/appengine/docs/standard/php7/runtime#application_startup

Also, looking more closely at the traceback leading to the 404 might give you some hints.

Here are some general pointers when migrating from one environment to the other (reversed but still useful): https://cloud.google.com/appengine/docs/flexible/php/migrating

Cheers

Upvotes: 1

Related Questions