Search code examples
httphttpsgoogle-cloud-platformgoogle-cloud-load-balancer

Allow http and https to point to my static website hosted on GCP bucket


Objective:

I want to allow https://example.com, http://example.com and www.example.com to point to my static website hosted on Google Cloud Storage bucket.

My Setup:

I am hosting a static website on Google Cloud Storage bucket.

  • The bucket called www.example.com
  • I have load balancer with https frontend and the bucket as backend.
  • In the Cloud DNS, I have CNAME record that point to the bucket.
  • I have A record that points my domain "example.com" to the https IP address of the load balancer front end.

With the above setup, https://example.com and www.example.com work fine.

I want to allow http too. So, I added another frontend to the load balancer "http". Then, I added the IP address of that frontend to the existing A record. So, now my A record has both IP addresses for http and https.

After doing that, http://example.com started working. However, https://example.com stopped working. Am I missing something?


Solution

    1. Delete the HTTP frontend and recreate it.
    2. Use the same IP address for the HTTP frontend that you are using for the HTTPS frontend.
    3. Delete the extra IP address from your DNS server.

    You will then have to wait for DNS to update which can take hours to a day. Your current (old) entries will need to expire (TTL).

    To verify that everything is set up correctly use an Internet service like MxToolbox to verify your DNS records.

    Why is your current setup not working? You have defined two IP addresses for the same website. Most DNS servers will round-robin those addresses, which means sometimes your website will resolve to one IP address (Load Balancer Frontend) and then to the other IP address (the other Frontend). However your frontends are configured per-protocol (HTTP/HTTPS), so you have a 50% chance of hitting the wrong frontend for the wrong protocol.