Having issues with redirects w/ Google Cloud Storage & Fastly


#1

I have successfully linked a bucket to the Fastly CDN, but am having real issues with trying to redirect pages. I have been using the following guide as instructed by Fastly.

Basically it goes like this - let’s say I have a domain called me.mydomain.com.

I add that as the domain, I make the origin storage.googleapis.com:443 and BOOM it works.

By it works, I mean that the webserver directory index works; when someone travels to http://me.mydomain.com, it will redirect to http://me.mydomain.com/index.html. Also, if I have a folder called /test/ and I travel to there, it will search for an index.html file in that directory and locate redirect to that file.

Now here is where things get quirky: If I want to let a client create an alias to me.mydomain.com, I need to create an override host. Because if I don’t, when I add my clients domain to the service, it will say that the bucket doesn’t exist.

So I create the override host as me.mydomain.com.storage.googleapis.com and I let the client create the following:
CNAME: clientdomain.com <- to -> me.mydomain.com

Now once I do that, the new domain directs to the bucket. However, the Google Cloud Storage directory index redirects stops working and I start getting XML data of just the file lists if I go straight to the root domain.

So my question is: is there a way to make the Google Cloud Storage default file redirects to work with an override host?

I really don’t want to resort to a user getting redirected every time they visit a website that is on GCS.


#2

So my question is: is there a way to make the Google Cloud Storage default file redirects to work with an override host?

The default behavior for GCS is one hostname to one bucket.

If you use the option to override with a default hostname and mask different incoming hostnames, to get the behavior you desire configure redirects or rewrites within the Fastly VCL for each path in the index.html.

Example:

if( req.url ~ "/$" ) {
        set req.url = req.url "index.html";

Otherwise, if the request is a for a directory - the resulting coding list will be displayed (index.html) vs a html page. When a file name is requested, content will be returned from the GCS bucket if it exists otherwise it will return some error.


#3

If you use c.storage.googleapis.com as your origin host then you don’t need to do this and also the 404 page setup on your bucket will work.