Hi All,
The objective is that I am in need of hosting a static website in a Private GCS bucket. On top of the bucket I'll use load balancer with Cloud Armor policies to restrict access.
I followed this blog https://medium.com/@thetechbytes/private-gcs-bucket-access-through-google-cloud-cdn-430d940ebad9
Created a similar setup in the project. The setup is as given below.
The issue is if I access the URL with it shows loads an XML format page with the list of objects inside the bucket. Only if I mention the path /index.html in the URL it loads to that page. I want to know how to write a LB routing rule to achieve the below.
If someone uses URL example.com it should automatically load as example.com/index.html
Hi @AnbuKLB ,
Can you try creating a URL map & then a URL path matcher as described in
For the --backend-bucket-path-rules=PATH=BUCKET argument, replace PATH with /*, as shown in the following example:
--backend-bucket-path-rules=/*=mybucket
Hi @kumards
I have not used backend buckets here. I only have private GCS bucket. I can't make it public. And so I didn't go with Backend buckets. I created a NEG and mapped everything as mentioned in the post. If backend buckets can be private please let me know I'll also try that setup. But the current setup is working for me. The only thing is I want to acheive the below.
If I enter the site name it should automatically redirects example.com -> example.com/index.html
Replying here in case it helps someone in the future. I had the same issue and I was able to solve it by inserting a pathRule with a urlRedirect, which redirects from the path `/` to the pathRedirect `/index.html`.
GCP examples for traffic management.
GCP documentation for URL Maps.
Here is an example in Terraform Code how I did my URL Map:
resource "google_compute_url_map" "cdn_lb" {
name = "cdn-lb"
description = "Load Balancer to redirect requests to bucket backend"
default_service = google_compute_backend_service.cdn_backend_service.id
host_rule {
hosts = ["*"]
path_matcher = "matcher1"
}
path_matcher {
name = "matcher1"
default_service = google_compute_backend_service.cdn_backend_service.id
path_rule {
paths = ["/"]
url_redirect {
path_redirect = "/index.html"
strip_query = true
}
}
}
}
Is your issue resolved I am facing the same issue can you guide what steps you followed to map it to index.html