Teknasyon Engineering

We develop innovative solutions for millions of users worldwide, with Zotlo, Rockads, Desk360…

Follow publication

Google Cloud Platform: Redirect 301 HTTPS on App Engine with nginx

Ercan (@flightlesstux)
Teknasyon Engineering
2 min readApr 15, 2021

--

I started to play with App Engine on Google Cloud Platform these days. I’m using a flexible environment with a custom runtime to run PHP in Docker. App Engine serving the content via HTTP and HTTPS as well. I checked the disable HTTP or redirect the HTTP traffic easily to HTTPS via Web UI but unfortunately, it’s not possible right now. Yes, you heard right, the basic feature is not supporting!

I check the document for (https://cloud.google.com/appengine/docs/standard/php7/application-security) I tried to set a 301 redirect via app.yaml file. Here is what I tried:

handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301

I deployed a new version of my app but App Engine still serving via HTTP and it doesn’t redirect to HTTPS when I requested insecure connection.

This time, I decided to give a shot to nginx. I opened my nginx-app.conf file and I wrote this:

server_name _;if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}

And Voila! It worked so perfectly. How I tried and understand this process you can see below.

➜  ~ curl -I http://ercan-ermis.ew.r.appspot.com/
HTTP/1.1 301 Moved Permanently
Date: Thu, 15 Apr 2021 07:03:34 GMT
Content-Type: text/html
Content-Length: 178
Server: nginx
Location: https://ercan-ermis.ew.r.appspot.com/
Via: 1.1 google

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Teknasyon Engineering

We develop innovative solutions for millions of users worldwide, with Zotlo, Rockads, Desk360, Getcontact, eSIM.io, Lisa AI and more.

Written by Ercan (@flightlesstux)

⌨️ Solution Architect, formerly DevOps Engineer Lead 👨‍👩‍👧‍👦 3x @AWSCommunity Builder 😶‍🌫️ Certified #AWS Solution Architect (SAA-C03) 🐍 #Python Dev♥️

No responses yet

Write a response