2

We are launching a PHP application into Google App Engine Flex Environment.

We have configured a custom domain. The desired behavior is that any request to http://custom.example.com will forward to https://custom.example.com

Currently, if you go to the appspot url, for example, http://project-name.appspot.com, that request does correctly forward to https://project-name.appspot.com

However, if you go to the custom domain, it does not forward to https. The application runs correctly, except that it is allowing http connection.

Google App Engine Documentation describing the available configuration files:
https://cloud.google.com/appengine/docs/flexible/php/configuring-your-app-with-app-yaml which states: Contents of the nginx-app.conf file will be included in the server section in the main nginx config file.

So, I am trying to create a nginx configuration that will force https. I tried this in the nginx-app.conf file:

listen 80;
server_name custom.example.com;
return 301 https://$server_name$request_uri;

But, with this config, in the browser, I get:

This page isn’t working

custom.example.com redirected you too many times.

ERR_TOO_MANY_REDIRECTS

I think I need a different nginx configuration but have not been able to find a working solution.

Community
  • 1
  • 1
Rob MacMillian
  • 576
  • 4
  • 14
  • Do you have a reverse proxy in front which points `https` to the same upstream over http, like cloudflare? as your not showing your `listen 443;` rules. – Lawrence Cherone Mar 23 '18 at 03:57
  • I don't have the full nginx configuration. The contents of the nginx-app.conf file will be added to the server section of the main nginx config file. I believe there is no reverse proxy. If you go to https : // custom.example.com directly, the site works. – Rob MacMillian Mar 23 '18 at 04:03
  • Try wrapping `if ($scheme = http) {return 301 https://$server_name$request_uri;}` – Lawrence Cherone Mar 23 '18 at 04:06
  • Related: https://stackoverflow.com/questions/49246049/how-to-force-ssl-on-google-app-engine-flexible-environment – Dan Cornilescu Mar 23 '18 at 04:29
  • THANKS! The solution on the above linked issue, solved my problems – Rob MacMillian Mar 23 '18 at 05:00

1 Answers1

1

Adding these lines to the nginx-app.conf file solved this issue.

set $test "";

if ($http_x_forwarded_proto = 'http') {
    set $test "http";
}

if ($test = 'http') {
    return 301 https://$host$request_uri;
}
Rob MacMillian
  • 576
  • 4
  • 14