Search code examples
phpgoogle-app-enginenginxapp-engine-flexiblegoogle-app-engine-php

How do I configure my nginx-app.conf file to serve /index.php if found in the supplied URL on app engine flexible?


I recently migrated a site to the flex environment from bluehost. With this migration, I'm aware that I need to configure my nginx-app.conf file to serve scripts/files in the way that I want, but I don't know how to do this.

I want to mimic hosting providers like bluehost, godaddy, hostgator etc... Where I can deploy a script to domain.com/path/ and when a request is made to that path: the domain.com/path/index.php is loaded if it exists, or it falls back to index.html or throws a 404 error

In addition: if a request is made directly to a script like so: domain.com/path/myscript.php then the appropriate myscript.php file is loaded if it exists, or throws a 404 error.

I have attempted to write my nginx-app.conf file as follows:

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

But when I click on any links after a deploy, it just stays on the same page.


Solution

  • After just monkeying around for ages, and dealing with the unbearably slow deployment times on the flex environment, I was able to come up with the following that works.

    location / {
      try_files $uri?$args $uri/index.php?$args;
    }