Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enforce HTTPS traffic to Google App Engine with custom domain?

I have a site on Google Domains (www.example.com) and it's hosted with Gcloud. I followed the instructions listed here to set up SSL and https: https://cloud.google.com/appengine/docs/standard/python/securing-custom-domains-with-ssl

Basically, I just ran gcloud beta app domain-mappings update example.com --certificate-management='AUTOMATIC'

Now I can indeed access https://example.com and https://www.example.com. But I can access the unsecure http version of those domains as well.

How can I set up my Google Domain to always use https? If someone types http://example.com, I want it to go to the https site instead.

Records: My naked domain (example.com) has 4 A records and 4 AAAA records.

My www.example.com domain has 1 CNAME record with alias=www.

like image 596
swagrov Avatar asked Feb 12 '18 17:02

swagrov


People also ask

How do I force Google domain to HTTPS?

Set SECURE_SSL_REDIRECT to True, and enable the SecurityMiddleware in your app, and any requests should automatically be redirected from HTTP to HTTPS. Save this answer. Show activity on this post.

How do I use custom domain in App Engine?

In the Google Cloud console, go to the Custom Domains tab of the App Engine Settings page. Click Add a custom domain. If your domain is already verified, the domain appears in the Select the domain you want to use section. Select the domain from the drop-down menu and click Continue.

How do I create a custom HTTPS domain?

In the list of frontend hosts, select the custom domain you want to enable HTTPS for containing your custom domain. Under the section Custom domain HTTPS, select Enabled, and select Front Door managed as the certificate source. Select Save. Continue to Validate the domain.


1 Answers

Have you tried setting secure: always in your handlers in your app.yaml?

handlers:
- url: /youraccount/.*
  script: accounts.app
  login: required
  secure: always

always

Requests for a URL that match this handler that do not use HTTPS are automatically redirected to the HTTPS URL with the same path. Query parameters are preserved for the redirect

https://cloud.google.com/appengine/docs/standard/python/config/appref#handlers_element

like image 51
Alex Avatar answered Sep 30 '22 09:09

Alex